A nullable reference type makes a possible null value explicit to the C# compiler. With `<Nullable>enable</Nullable>` in the project file, write `string?` when a property may be null. The compiler can then warn about potential null problems. The annotation does not change the fact that a reference can hold null at runtime. section 2.8 section 5.2.2
Model an optional command-line value
An `Options` record declares `public string? Text` even though the command-line parser requires the argument. The parser will not create the options object without that argument, but the compiler cannot infer the parser’s guarantee. The nullable annotation resolves the warning by acknowledging what the compiler can establish. section 2.8
Choose an annotation that matches the property’s intended use:
- Use `string? Title` if a missing title is acceptable. section 5.2.2
- If a title is required, keep `string Title` and initialize it, or require it through a constructor. A nullable annotation would silence the warning while also allowing an unwanted null title. section 5.2.2
Listing 5.7 Book constructor
public class Book
{
public int Id { get; set; } #1
public string Title { get; set; } #2
public Book(string title) #3
{
Title = title; #4
}
}
The `Book` constructor shows how to assign a non-nullable `Title` when creating an entity; passing `null` produces a compiler warning. section 5.2.2
Return types need the same care. `Comic? GetComic` reflects both a failed HTTP lookup and the possibility that valid JSON contains the value `null`, which deserializes to null. Callers can check the result before using it. Keep nullable checking enabled rather than disabling it merely to remove warnings. section 4.3 section 5.2.2

