Illustrates the use of the switch statement to compare string values
/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy
Publisher: Sybex;
ISBN: 0782129110
*/
/*
Example4_6.cs illustrates the use of
the switch statement to compare string values
*/
public class Example4_6
{
public static void Main()
{
string planetName = "Saturn"; // sixth planet from the Sun
switch (planetName)
{
case "Mercury":
System.Console.WriteLine(1);
break;
case "Venus":
System.Console.WriteLine(2);
break;
case "Earth":
System.Console.WriteLine(3);
break;
case "Mars":
System.Console.WriteLine(4);
break;
case "Jupiter":
System.Console.WriteLine(5);
break;
case "Saturn":
System.Console.WriteLine(6);
break;
case "Uranus":
System.Console.WriteLine(7);
break;
case "Neptune":
System.Console.WriteLine(8);
break;
case "Pluto":
System.Console.WriteLine(9);
break;
default:
System.Console.WriteLine("Planet unknown");
break;
}
}
}
Related examples in the same category