开发者

In switch statement can we use enum in C# [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly开发者_StackOverflow中文版 broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

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


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();
   }
}


Have a look at

Lesson 17: Enums


Ya,you can use enums in switch statement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜