multiple case c# code example
Example 1: switch expression c# multiple cases
var switchValue = 3;
var resultText = switchValue switch
{
1 or 2 or 3 => "one, two, or three",
4 => "four",
5 => "five",
_ => "unknown",
};
Example 2: can you have multiple statement in a case c#
switch (value)
{
case 1: case 2: case 3:
break;
case 4: case 5: case 6:
break;
default:
break;
}
Example 3: multi case in c#
switch (value)
{
case var s when new[] { 1,2,3 }.Contains(s):
break;
case var s when new[] { 4,5,6 }.Contains(s):
break;
default:
break;
}