Skip to content

Null Handling in C#

This hub groups the C# features that directly deal with null values, null-safe access, and nullability contracts.

Use this section when the problem is one of these:

  • returning a fallback when a value is missing
  • navigating an object graph that may contain nulls
  • representing optional data explicitly
  • expressing nullability rules in APIs and models

If the feature is only indirectly related to nulls, it should not appear here.

FeatureIntroduced InWhy it belongs hereGuide
Null-coalescingC# 2.0Provides fallback values for null results.Guide
Null-coalescing assignmentC# 8.0Lazily assigns a default only when null.Guide
Null-conditionalC# 6.0Safely navigates possibly null receivers.Guide
Null-conditional assignmentC# 14.0Assigns through ?. or ?[] only when the receiver exists.Guide
Nullable value typesC# 2.0Represents optional value types.Guide
Nullable reference typesC# 8.0Makes nullability part of the type system.Guide
  1. Start with Nullable reference types if you want better API and model design.
  2. Read Null-conditional and Null-coalescing for everyday usage patterns.
  3. Add Null-coalescing assignment when you need lazy initialization.