Possible Duplicate:
Multiple Cases in 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;
}
精彩评论