Skip to content

C# Feature - Nullable reference types

Nullable reference types use annotations and flow analysis so the compiler can warn when null may violate a reference type contract.

C# 8.0 (2019)

string name = FindName();
Console.WriteLine(name.Length);
string? name = FindName();
Console.WriteLine(name?.Length ?? 0);
  • Enable nullable context project-wide instead of file by file when possible.
  • Treat warnings as design feedback, not just compiler noise.