tags:

views:

149

answers:

3

Suppose we want to give condition using switch statement with the use of enum. Can we do that? If yes, then how?

+12  A: 

Yes, it works fine. The Lesson 17: Enums article offers this example:

// declares the enum
public enum Volume
{
   Low,
   Medium,
   High
}

// demonstrates how to use the enum

class EnumSwitch
{
   static void Main()
   {
      // create and initialize 
      // instance of enum type
      Volume myVolume = Volume.Medium;

      // make decision based
      // on enum value
      switch (myVolume)
      {
         case Volume.Low:
            Console.WriteLine("The volume has been turned Down.");
            break;
         case Volume.Medium:
            Console.WriteLine("The volume is in the middle.");
            break;
         case Volume.High:
            Console.WriteLine("The volume has been turned up.");
            break;
      }
      Console.ReadLine();
   }
}
Scott Stafford
A: 

Have a look at

Lesson 17: Enums

astander
A: 

Ya,you can use enums in switch statement.

Nakul Chaudhary