C# Case Expression via Extension Methods

5 minute read Published:

As a veteran C# developer yourself, I’m sure you’re familiar with the switch statement. Since it is a statement this means you cannot effectively use this ever-so-useful construct in an expression, such as in a LINQ query. This is a shame, and it irks me greatly that I have to resort to emulating the switch behavior with a series of chained ternary operators (a ? b : c ? d : e ?