Switch Expression in C# 8

The switch statement in C# was completely inherited from the C programming language and it has always been very verbose.

C# 8 introduces a new streamlined way to write conditional code as an expression.

The switch expression has some limitations (by the fact that is an expression and must always return a value) so you can’t replace all usages of switch statements in your projects. However, in most cases, the replacement can be done, and I would recommend you to always use the new syntax over the old one when possible.

The switch expression also support a new set of patterns like property patterns, tuple patterns and positional patterns that help you write complex pattern matching scenarios in a few lines of code.