C# › Records & Pattern Matching

How does switch pattern matching improve code?

Intermediate

Answer

switch expressions match on type, constant, relational and property patterns, returning a value concisely and forcing exhaustive, readable branching.
string Size(int n) => n switch { < 10 => "small", < 100 => "medium", _ => "large" };
Real-world example Mapping an HTTP status or an enum to a message without long if/else chains.