Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在switch语句中,我们可以在C中使用enum吗#_C#_.net_Enums - Fatal编程技术网

C# 在switch语句中,我们可以在C中使用enum吗#

C# 在switch语句中,我们可以在C中使用enum吗#,c#,.net,enums,C#,.net,Enums,假设我们想使用switch语句和enum给出条件。我们能做到吗? 如果是,那么怎么做?是的,它工作正常。本文提供了以下示例: // declares the enum public enum Volume { Low, Medium, High } // demonstrates how to use the enum class EnumSwitch { static void Main() { // create and initialize

假设我们想使用switch语句和enum给出条件。我们能做到吗? 如果是,那么怎么做?

是的,它工作正常。本文提供了以下示例:

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


是的,您可以在switch语句中使用enum。

您尝试过吗?