在c#中具有多个常量表达式的switch语句.是否可以? [英] 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语句.是否可以?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文