Mega Code Archive

 
Categories / C# / Language Basics
 

Switch With Default Values

/* Learning C#  by Jesse Liberty Publisher: O'Reilly  ISBN: 0596003765 */  using System; public class SwitchWithDefaultValues  {      static void Main()      {          const int Democrat = 0;          const int Republican = 1;          const int Progressive = 2;          // hard wire to Republican          int myChoice = 5;          // switch on the value of myChoice          switch (myChoice)          {              case Democrat:                  Console.WriteLine("You voted Democratic.\n");                  break;              case Republican:                  Console.WriteLine("You voted Republican.\n");                  break;              case Progressive:                  Console.WriteLine("You voted Progressive.\n");                  break;              default:                  Console.WriteLine("You did not make a valid choice.");                  break;          }          Console.WriteLine("Thank you for voting.");      }  }