0Pricing
C# Academy · Lesson

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 warnings

All lessons in this course

  1. Enabling & Understanding NRT
  2. Annotations: ?, !, MaybeNull & NotNull
  3. Null-Conditional & Null-Coalescing Operators
  4. Migrating a Codebase to NRT
← Back to C# Academy