多宗开关: [英] Multiple Cases in Switch:
问题描述
我相信我已经看到了这个地方,但我不记得,如果它是一个不同的语言,或者如果我只是不记得语法很好。
I believe I've seen this somewhere, but I don't recall if it was a different language, or if I just can't remember the syntax well.
有没有通过多个case语句下跌不说明案值的方法:反复
Is there a way to fall through multiple case statements without stating case value: repeatedly?
我知道这个作品:
switch (value)
{
case 1:
case 2:
case 3:
//do some stuff
break;
case 4:
case 5:
case 6:
//do some different stuff
break;
default:
//default stuff
break;
}
但我想要做这样的事情:
but I'd like to do something like this:
switch (value)
{
case 1,2,3:
//Do Something
break;
case 4,5,6:
//Do Something
break;
default:
//Do the Default
break;
}
这是语法,我从不同的语言思维,还是我失去了一些东西?
Is this syntax I'm thinking of from a different language, or am I missing something?
谢谢!
推荐答案
有在C没有语法++也不C#你提到的第二个方法。
There is no syntax in C++ nor C# for the second method you mentioned.
有没有错,你的第一个方法。然而,如果你有非常大的范围内,只要使用了一系列的if语句。
There's nothing wrong with your first method. If however you have very big ranges, just use a series of if statements.
这篇关于多宗开关:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!