It is possible to convert this:
int x = 1;
string xString;
switch (x)
{
case 1:
xString = "1";
break;
case 2:
xString = "2";
break;
default:
xString = "default";
break;
}
Console.WriteLine(xString);
into this:
int x = 1;
string xString = x switch
{
1 => "1",
2 => "2",
_ => "default",
};
Console.WriteLine(xString);
But what would be the syntax to set xString's value to the same value with multiple cases without creating a lambda line for each case?
int x = 1;
string xString;
switch (x)
{
case 1:
xString = "1";
break;
case 2:
case 4:
xString = "even numbers";
break;
default:
xString = "default";
break;
}
Console.WriteLine(xString);