A string can control a switch statement : String Switch : String C# Examples


C# Examples » String » String Switch »

 

A string can control a switch statement









    
using  System;  
  
class  MainClass  {    
    public  static  void  Main()  {    
        string[]  strs  =  {  "one",  "two",  "three",  "two",  "one"  };  
  
        foreach(string  s  in  strs)  {  
            switch(s)  {  
                case  "one":  
                    Console.Write(1);  
                    break;  
                case  "two":  
                    Console.Write(2);  
                    break;  
                case  "three":  
                    Console.Write(3);  
                    break;  
            }  
        }  
        Console.WriteLine();  
  
    }  
}
    
   
  
   



Output

12321


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo String
» String Switch