Check int value with Switch branch - CSharp Language Basics

CSharp examples for Language Basics:switch

Description

Check int value with Switch branch

Demo Code

using System;/*from w w  w  .  ja  v  a  2 s. c o  m*/
class Dishwasher
{
   public static void Main()
   {
      int programSelection;
      Console.WriteLine("Please select a dishwashing program: ");
      Console.WriteLine("1: Economy   2: Intensive    3: Universal");
      programSelection = Convert.ToInt32(Console.ReadLine());
      switch(programSelection)
      {
         case 1:
            Console.WriteLine("You have selected the Economy program");
            Console.WriteLine("Nice environmentally friendly choice");
            break;
         case 2:
             Console.WriteLine("You have selected the Intensive program");
             Console.WriteLine("Good for week old unwashed dishes");
             break;
         case 3:
             Console.WriteLine("You have selected the Universal program");
             Console.WriteLine("OK! I'm ready for anything. Just try me out.");
             break;
         default:
             Console.WriteLine("Invalid selection. You must choose a number " + "between 1 and 3");
             break;
      }
   }
}

Result


Related Tutorials