A string can control a switch statement : String : Data Types C# Source Code


Custom Search

C# Source Code » Data Types » String »

 

A string can control a switch statement









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// A string can control a switch statement. 
 
using System; 
 
public class StringSwitch {  
  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(); 
 
  } 
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Data Types
» String