C# allows the use of switch statements similar to the example provided. Here is how you can write it idiomatically in C#:
Here’s a basic switch.
You can use commas to separate multiple expressions in the same case statement. We use the optional default case in this example as well.
switch without an expression is an alternate way to express if/else logic. Here we also show how the case expressions can be non-constants.
A type switch compares types instead of values. You can use this to discover the type of an object. In this example, the variable t will have the type corresponding to its clause.
When you run this C# code, it will produce the following output: