Mega Code Archive

 
Categories / C# / Language Basics
 

Switch Values Fall Through

/* 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.\n");                  break;              case "CompassionateRepublican": // fall through              case "Republican":                  Console.WriteLine("You voted Republican.\n");                  Console.WriteLine("Don't you feel compassionate?");                  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.");      }  }