Switch Values Fall Through

image_pdfimage_print

   

/*
Learning C# 
by Jesse Liberty

Publisher: O'Reilly 
ISBN: 0596003765
*/
 using System;

public class ValuesFallThrough
 {
     static void Main()
     {
         String myChoice = "NewLeft";

         // switch on the string value of myChoice
         switch (myChoice)
         {
             case "NewLeft":
                 Console.WriteLine(
                  "The NewLeft members are voting Democratic.");
                 goto case "Democrat";
             case "Democrat":
                 Console.WriteLine("You voted Democratic.
");
                 break;
             case "CompassionateRepublican": // fall through
             case "Republican":
                 Console.WriteLine("You voted Republican.
");
                 Console.WriteLine("Don't you feel compassionate?");
                 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.");
     }
 }