We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Bringing C# nullability into existing code - dammit is not the answer! - Maarten Balliauw
Learn how to effectively bring C# nullability into your existing code, without resorting to hacks, and understand the various annotations, attributes, and operators available to you.
- C# nullability is a design-time safety feature, not a runtime safety feature.
-
The
?(nullable annotation) can be added to method parameters and return types to indicate that they can be null. -
The
nonnullattribute can be used to explicitly specify that a property or field cannot be null. -
The
?(nullable annotation) can be used to make a non-nullable reference type nullable, but this is generally considered an anti-pattern and should be avoided. - The compiler and IDE can be configured to control the level of nullability warnings and errors.
-
The
nullableattribute can be used to specify that a property or field can be null. -
The
requiredkeyword can be used to specify that a property or field cannot be null. -
The
nullablecontext attribute can be used to specify the nullability context for a project or solution. -
The
?(nullable annotation) can be used to specify that a parameter or return type can be null, but the compiler and IDE will not perform any additional checks. -
The
nodiscardattribute can be used to specify that a property or field will always return a non-null value. -
The
??(null-coalescing operator) can be used to provide a default value in case a property or field is null. -
The
??=(null-coalescing assignment operator) can be used to assign a default value in case a property or field is null. -
The
??!(null-coalescing assignment operator) can be used to assign a default value in case a property or field is null. -
The
!(null-forgiving operator) can be used to explicitly specify that a value is not null. -
The
??(null-coalescing operator) can be used to provide a default value in case a property or field is null.
Note: These are just some key takeaways from the text, and are not necessarily a comprehensive summary of the talk.