Here is a switch function:
public static void Main(string[] args)
{
int level = 5;
var indicator = level switch
{
1 => "C",
2 => "R",
3 => "R",
5 => "R",
6 => "R",
_ => "D"
};
Console.ReadKey();
}
Here all the 2,3,5,6 will return the same result "R", I try to add the key word "or", but there will be a Compile Error. Is there a way to simplify it? thanks.
public static void Main(string[] args)
{
int level = 5;
var indicator = level switch
{
1 => "C",
2 or 3 or 5 or 6 => "R",
_ => "D"
};
Console.ReadKey();
}