的错误:
A switch expression or case label must be a bool, char, string, integral, enum, or corresponding nullable type
代码是自我解释的。它告诉你switch表达式必须是这些类型中的一个:sbyte,byte,short,ushort,int,uint,long,ulong,char,string。或C#语言规范建议
exactly one user-defined implicit conversion (§6.4) must exist from the type of the switch expression to one of the following possible governing types: sbyte, byte, short, ushort, int, uint, long, ulong, char, string, or, a nullable type corresponding to one of those types.
而且你可以看到,背景色,这里的返回类型和它没有任何满足上述规则,因此错误。
,你可以做这样的
switch (btn.BackColor.Name)
{
case "Green":
break;
case "Red":
break;
case "Gray":
break;
}