C# 8.0 Nullable References
Use C# 8.0 nullable references to signal a possible NullReferenceException.
To prevent a NullReferenceException
, we should check and defend against null
. The real question is when an object reference might be null
and therefore when we should add a null
check. That’s precisely what C# 8.0 solves with the nullable references feature.
So far, all references have been nullable by default. But C# 8.0 nullable references change this assumption: all reference variables are now non-nullable by default. This means that when we access the properties or methods of references that might be null
, it results in compiler warnings or errors.
This is a big change. Therefore, we need to now turn this feature on at the project level ...
Get hands-on with 1400+ tech skills courses.