liveBook · Manning

Missing value

As explained in .NET in Action, Second Edition

A null value indicates that a reference or nullable value does not refer to an object or contain a non-null value.

A null reference does not refer to an object. In C#, reference types such as string can be null; nullable reference annotations make that possibility explicit so the compiler can check for potential problems. section 2.8

Listing 2.15 Options Text property without the shorthand
public record Options
{
  private string? _text;      #1
  
  [Value(0, Required = true)]
  public string? Text
  {
    get
    {
      return _text;           #2
    }
    init                      #3
    {
      _text = value;          #4
    }
  }
}

The Options.Text property and its backing field are both marked nullable with string?. section 2.8

A required command-line parameter may still prompt a compiler warning: the parser knows it will not create Options without the parameter, but the compiler does not. Nullable reference types support compile-time checks, while backward compatibility means C# still has multiple null-related operators and nullable types. section 2.8

How .NET in Action, Second Edition covers it

How deep it goes
Defines null references and explains nullable annotations, compiler warnings, and backward compatibility without detailing runtime internals.
Examples
Shows a nullable string property for command-line text and a warning caused by the parser's required-parameter guarantee.
What it assumes
Assumes familiarity with C# reference types and project nullable settings.
What you can do after
Apply nullable reference annotations to option properties and use compiler checks to identify potential null-handling problems.
How it connects
Connects null references with C# reference types, nullable reference types, properties, and compile-time static analysis.

Also explained in

Compare how 35 books explain missing value →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.