Switch statement with multiple constant-expression in c#. Is it possible?(在 C# 中具有多个常量表达式的 switch 语句.是否可以?)
问题描述
可能重复:
Switch中的多个案例:
是否可以执行多个常量表达式的 switch 语句,例如
Is it possible to do a multiple constant-expression switch statement like
switch (i) {
case "run","notrun", "runfaster": //Something like this.
DoRun();
break;
case "save":
DoSave();
break;
default:
InvalidCommand(command);
break;
}
推荐答案
是的,是.您可以为同一部分使用多个案例标签:
Yes, it is. You can use multiple case labels for the same section:
switch (i)
{
case "run":
case "notrun":
case "runfaster":
DoRun();
break;
case "save":
DoSave();
break;
default:
InvalidCommand(command);
break;
}
这篇关于在 C# 中具有多个常量表达式的 switch 语句.是否可以?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!