Switch With Default Values

image_pdfimage_print

   

/*
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.
");
                 break;
             case Republican:
                 Console.WriteLine("You voted Republican.
");
                 break;
             case Progressive:
                 Console.WriteLine("You voted Progressive.
");
                 break;
             default:
                 Console.WriteLine("You did not make a valid choice.");
                 break;
         }
         Console.WriteLine("Thank you for voting.");
     }
 }