Switch Statements & Expressions
Prerequisites: Conditionals
Like Java, C# has both an older statement form and a modern switch expression that produces a value directly:
int day = 3;
string name = day switch {
1 => "Monday",
2 => "Tuesday",
3 => "Wednesday",
_ => "Unknown", // "_" is the default/discard case
};
Console.WriteLine(name); // Wednesday
The switch expression needs no break at all, and — combined with
pattern matching (Level 3) — can match on a value's shape, not
just its exact value.