patterncsharpCritical
Multiple cases in switch statement
Viewed 0 times
switchmultiplestatementcases
Problem
Is there a way to fall through multiple case statements without stating
I know this works:
but I'd like to do something like this:
Is this syntax I'm thinking of from a different language, or am I missing something?
case value: repeatedly?I know this works:
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?
Solution
There is no syntax in C++ nor C# for the second method you mentioned.
There's nothing wrong with your first method. If however you have very big ranges, just use a series of if statements.
There's nothing wrong with your first method. If however you have very big ranges, just use a series of if statements.
Context
Stack Overflow Q#68578, score: 374
Revisions (0)
No revisions yet.