nullable reference types
A C# compiler feature that tracks whether each reference might be null and warns when code uses one without checking.
In more detail
Switch it on with <Nullable>enable</Nullable>; every template since .NET 6 does. With it on, string means a value that is there and string? means one that may be missing. The warnings do not stop the build unless warnings are treated as errors.
Example
<Nullable>enable</Nullable>Related terms
- null-keyword — A special value meaning a reference points at nothing.
- null-forgiving operator — A postfix exclamation mark, as in code!.Length, that tells the compiler to assume a value is not null and suppress the nullable warning.
- CS8602 — The C# compiler warning 'dereference of a possibly null reference', raised when code uses a value that might be null without checking it.
- TreatWarningsAsErrors — The build property that turns every compiler and analyzer warning into an error, so code with warnings fails to build.
Taught in
- What is .NET? Runtime vs SDK, and LTS vs STS — Modern .NET Core, C# & Enterprise Microservices
- The C# Language: Types, Variables, and Flow Control — Modern .NET Core, C# & Enterprise Microservices
- Solutions, Projects, and Target Frameworks — Modern .NET Core, C# & Enterprise Microservices
- Directory.Build.props, global.json and Central Packages — Modern .NET Core, C# & Enterprise Microservices
- Entity Framework Core: Code First and Migrations — Modern .NET Core, C# & Enterprise Microservices
- Manual Object Mapping — Modern .NET Core, C# & Enterprise Microservices