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.
It silences a real warning, so a genuine null slips through to crash at run time.
In more detail
It changes only the warning, not run-time behaviour: if the value is null the program still throws. Use it only where you can prove the value is present.
Related terms
- nullable reference types — A C# compiler feature that tracks whether each reference might be null and warns when code uses one without checking.
- CS8602 — The C# compiler warning 'dereference of a possibly null reference', raised when code uses a value that might be null without checking it.
Taught in
- The C# Language: Types, Variables, and Flow Control — Modern .NET Core, C# & Enterprise Microservices
- Async and Await: Managing Concurrency — Modern .NET Core, C# & Enterprise Microservices
- The Options Pattern: Strongly Typed Configuration — Modern .NET Core, C# & Enterprise Microservices