Skip to main content
Indentation
Source Link
Ola Ström
  • 5.5k
  • 6
  • 31
  • 51

I want to use switch, but I have many cases, is there any shortcut? So
So far the only solution I know and tried is:

switch (number)
{
    case 1: something; break;
    case 2: other thing; break;
    ...
    case 9: .........; break;
}

What I hope I'm able to do is something like:

switch (number)
{
    case (1 to 4): do the same for all of them; break;
    case (5 to 9): again, same thing for these numbers; break;
}

I want to use switch, but I have many cases, is there any shortcut? So far the only solution I know and tried is:

switch (number)
{
case 1: something; break;
case 2: other thing; break;
...
case 9: .........; break;
}

What I hope I'm able to do is something like:

switch (number)
{
case (1 to 4): do the same for all of them; break;
case (5 to 9): again, same thing for these numbers; break;
}

I want to use switch, but I have many cases, is there any shortcut?
So far the only solution I know and tried is:

switch (number)
{
    case 1: something; break;
    case 2: other thing; break;
    ...
    case 9: .........; break;
}

What I hope I'm able to do is something like:

switch (number)
{
    case (1 to 4): do the same for all of them; break;
    case (5 to 9): again, same thing for these numbers; break;
}
Post Closed as "Duplicate" by Peter Duniho c#

I want to use switch, but I have many cases, is there any shortcut? So far the only solution I know and tried is:

switch (number)
{
case 1: something; break;
case 2: other thing; break;
...
case 9: .........; break;
}

What I hope I'm able to do is something like:

switch (number)
{
case (1 to 4): do the same for all of them; break;
case (5 to 9): again, same thing for these numbers; break;
}

Thanks in advance for the help!

I want to use switch, but I have many cases, is there any shortcut? So far the only solution I know and tried is:

switch (number)
{
case 1: something; break;
case 2: other thing; break;
...
case 9: .........; break;
}

What I hope I'm able to do is something like:

switch (number)
{
case (1 to 4): do the same for all of them; break;
case (5 to 9): again, same thing for these numbers; break;
}

Thanks in advance for the help!

I want to use switch, but I have many cases, is there any shortcut? So far the only solution I know and tried is:

switch (number)
{
case 1: something; break;
case 2: other thing; break;
...
case 9: .........; break;
}

What I hope I'm able to do is something like:

switch (number)
{
case (1 to 4): do the same for all of them; break;
case (5 to 9): again, same thing for these numbers; break;
}
edited tags
Link
DarkDust
  • 92.7k
  • 19
  • 198
  • 231
Capitalized letters that needed to be capitalized.
Source Link
Loading
Source Link
user3022162
  • 1.7k
  • 2
  • 11
  • 4
Loading