The switch Statement : Switch : Statement C# Examples


C# Examples » Statement » Switch »

 

The switch Statement





The general form of the switch statement is




    
switch(expression)  {
      case  constant1:
              statement  sequence  
              break;
      case  constant2:
              statement  sequence  
              break;
      case  constant3:
              statement  sequence  
              break;
      .
      .
      .
      default:
            statement  sequence
            break;
}
    
   
  
   


The switch expression must be of an integer type, such as char, byte, short, or int, or of type string .
The default statement sequence is executed if no case constant matches the expression.
The default is optional.
If default is not present, no action takes place if all matches fail.
When a match is found, the statements associated with that case are executed until the break is encountered.




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Statement
» Switch