Enabling & Understanding NRT
Enable nullable context, understand nullable vs non-nullable reference types, and read compiler warnings.
The Billion Dollar Mistake
Tony Hoare (inventor of null) called it his 'billion dollar mistake'. In C#, any reference type could be null by default, making NullReferenceException the most common runtime crash. Nullable Reference Types (NRT) fix this at the compiler level.
Enabling the Nullable Context
Enable NRT globally in your project file or per-file with directives. Once enabled, the compiler treats reference types as non-nullable by default.
<!-- In .csproj — enable for the whole project -->
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>
// Or per-file:
#nullable enable
// ... code with NRT warnings
#nullable disable
// ... code without NRT warningsAll lessons in this course
- Enabling & Understanding NRT
- Annotations: ?, !, MaybeNull & NotNull
- Null-Conditional & Null-Coalescing Operators
- Migrating a Codebase to NRT