C# nullable reference types
Short answer
Nullable reference types let you mark which references may be null. In a nullable-aware context the compiler warns when you dereference something that might be null. [S1][S2]
Points
- The goal is fewer
NullReferenceExceptions. [S1] TvsT?are the same .NET type; the difference is static analysis. [S2]- Enable the feature with
<Nullable>enable</Nullable>or#nullablepragmas. [S1][S2] - The null-forgiving operator and null warnings are optional language features. [S2]
Claims
- id: C1 claim: Nullable references aim to reduce NullReferenceException. source: S1 evidence: "minimize the chance your code throws System.NullReferenceException"
- id: C2 claim: You can express which references allow null. source: S1 evidence: "express which references are intended to allow null"
- id: C3 claim: T and T? are the same .NET type at runtime. source: S2 evidence: "a variable of type T? are the same .NET type"
- id: C4 claim: Null-forgiving and null warnings are optional features. source: S2 evidence: "null-forgiving operator are optional language features"
Sources
- [S1] Nullable reference types - C#. Microsoft Learn. https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references . License: CC BY 4.0 (dotnet/docs). Accessed 2026-11-05.
- [S2] Nullable reference types. Microsoft Learn. https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/nullable-reference-types . License: CC BY 4.0 (dotnet/docs). Accessed 2026-11-05.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
Source notice: .NET documentation © Microsoft. Licensed under Creative Commons Attribution 4.0 International (https://github.com/dotnet/docs/blob/main/LICENSE).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Microsoft Learn, Nullable reference types - C#, CC BY 4.0 (dotnet/docs); Microsoft Learn, Nullable reference types, CC BY 4.0 (dotnet/docs).
Cite this
iinventedlight. 2026. "C# nullable reference types: string vs string?" iinventedlight Library, iil:note:m8f4jqgd, version of 2026-11-04. https://iinventedlight.com/library/notes/csharp-nullable-reference-types/. License: CC-BY-4.0.
@misc{iil_note_m8f4jqgd,
author = {{iinventedlight}},
title = {{C\# nullable reference types: string vs string?}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/csharp-nullable-reference-types/},
note = {Permanent ID iil:note:m8f4jqgd. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/csharp-nullable-reference-types.md.