是的,C#中的switch語句支持枚舉類型。枚舉類型在C#中被視為一種整數類型,因此可以在switch語句中使用。示例如下:
enum Color
{
Red,
Blue,
Green
}
Color color = Color.Red;
switch (color)
{
case Color.Red:
Console.WriteLine("The color is red");
break;
case Color.Blue:
Console.WriteLine("The color is blue");
break;
case Color.Green:
Console.WriteLine("The color is green");
break;
default:
Console.WriteLine("Unknown color");
break;
}