How to check for multiple switch statements in C #

I need to check multiple statements in a switch statement to check as

 int a=5; 
 switch(a) 
 { 
     case 4,5:
         console.write("its from 4 to 5);
         break; 
 }

      

+2


a source to share


4 answers


You want to do:

case 4:
case 5:
//Code goes here.
break;

      



Remember though C # doesn't let you fail, so you can't do:

    case 4:
    //Do some stuff here
    //fall through to 5
    case 5:
    //Code goes here.
    break;

      

+12


a source


In C #, you make stacks for this:

case 4:
case 5:
   //do something
   break;
case 6:
   //do something

      



and etc.

+3


a source


This allows for multiple cases for 1 value.

int a=5; 
 switch(a) 
 { 
     case 4:
        // Do work here
        goto case 5;
     case 5:
         console.write("its from 4 to 5);
         break; 
 }

      

or

This gives two shortcuts.

 switch(a) 
 { 
     case 4:
     case 5:
         console.write("its from 4 to 5);
         break; 
 }

      

+3


a source


Here's how ..

 int a=5; 
 switch(a) 
 { 
     case 4:
     case 5:
         console.write("its from 4 to 5);
         break; 
 }

      

+2


a source







All Articles