discard
The underscore _, used in a pattern to match anything, such as the final catch-all arm of a switch expression.
In more detail
A discard arm guarantees every input gets an answer, but it also silences the exhaustiveness warning. Leave it off when the set of values is closed, such as an enum, so that new members are flagged.
Example
_ => "many"Related terms
- switch expression — A switch construct that produces a value, with one arm per case and no fall-through between them.
- exhaustiveness — The property of a switch expression whose arms cover every possible input value, which the compiler checks for you.
Taught in
- The C# Language: Types, Variables, and Flow Control — Modern .NET Core, C# & Enterprise Microservices
- Records, Pattern Matching, and Modern C# — Modern .NET Core, C# & Enterprise Microservices