exhaustiveness
The property of a switch expression whose arms cover every possible input value, which the compiler checks for you.
In more detail
For an enum or other closed set of values, the compiler can list exactly which cases are missing. A non-exhaustive switch expression compiles with warning CS8509 and throws SwitchExpressionException if an unhandled value arrives at run time.
Related terms
- CS8509 — The C# compiler warning that a switch expression does not handle all possible input values, naming one that no arm matches.
- switch expression — A switch construct that produces a value, with one arm per case and no fall-through between them.
- discard — The underscore _, used in a pattern to match anything, such as the final catch-all arm of a switch expression.
Taught in
- Records, Pattern Matching, and Modern C# — Modern .NET Core, C# & Enterprise Microservices