Use a char type value to control the switch statement in CSharp

Description

The following code shows how to use a char type value to control the switch statement.

Example


/*  w w w  .j a  va2s .  c  o  m*/
using System; 
 
public class MainClass {     
  public static void Main() { 
    char ch; 
 
    for(ch='A'; ch<= 'E'; ch++) 
      switch(ch) { 
        case 'A':  
          Console.WriteLine("ch is A"); 
          break; 
        case 'B':  
          Console.WriteLine("ch is B"); 
          break; 
        case 'C':  
          Console.WriteLine("ch is C"); 
          break; 
        case 'D':  
          Console.WriteLine("ch is D"); 
          break; 
        case 'E':  
          Console.WriteLine("ch is E"); 
          break; 
      }     
  }   
}

The code above generates the following result.





















Home »
  C# Tutorial »
    C# Language »




C# Hello World
C# Operators
C# Statements
C# Exception