是否可以执行多个常量表达式切换语句,如
switch (i) {
case "run","notrun", "runfaster": //Something like this.
DoRun();
break;
case "save":
DoSave();
break;
default:
InvalidCommand(command);
break;
}
答案 0 :(得分:42)
Yes, it is。您可以为同一部分使用多个案例标签:
switch (i)
{
case "run":
case "notrun":
case "runfaster":
DoRun();
break;
case "save":
DoSave();
break;
default:
InvalidCommand(command);
break;
}