LANGUAGE
Switch arm guard
A switch arm is eligible only when its pattern matches and its guard evaluates true.
Formal Syntax & Structure
csharp syntaxcsharp
pattern when condition => resultWorking Example
Example Snippetcsharp
int x = 3;System.Console.WriteLine(x switch { int n when n > 0 => "positive", _ => "other" });