Switch for int type : Switch « Language Basics « C# / C Sharp






Switch for int type

/*
 * C# Programmers Pocket Consultant
 * Author: Gregory S. MacBeth
 * Email: gmacbeth@comporium.net
 * Create Date: June 27, 2003
 * Last Modified Date:
 */
using System;

namespace Client.Chapter_4___Program_Control
{
  public class MyMainClass1
  {
    static void Main(string[] args)
    {
      int a = 0;
      Console.ReadLine();

      switch (a)
      {
        case 1:
          Console.WriteLine("One");
          break;
        case 2:
          Console.WriteLine("Two");
          break;
        default:
          Console.WriteLine("?");
          break;

      }
    }
  }
}

           
       








Related examples in the same category

1.Simulate a conveyor beltSimulate a conveyor belt
2.Demonstrate the switchDemonstrate the switch
3.Use a char to control the switchUse a char to control the switch
4.Empty cases can fall throughEmpty cases can fall through
5.Illustrates the use of the switch statementIllustrates the use of the switch statement
6.Illustrates the use of the switch statement to compare string valuesIllustrates the use of the switch statement to compare string values
7.Switch statement containing a branch with no statements: causes a 'fall-through' to the next branchSwitch statement containing a branch with no statements: causes a 'fall-through' to the next branch
8.Switch ValuesSwitch Values
9.Switch With Default ValuesSwitch With Default Values
10.Switch Values Fall ThroughSwitch Values Fall Through
11.Switch based console menuSwitch based console menu