使用什么来获取typeof(Enum)

时间:2015-04-28 06:07:19

标签: c# enums

我创建了一个看起来像

的枚举
namespace MyNamespace.something
{
   public enum FuncResultCode
   {
      SUCCESS,
      MISSING_INFO,
      UNALLOWED_CHANGES
   }
}

当我在此枚举上使用typeof时,我会收到以下错误

Console.WriteLine(" " + typeof(FuncResultCode))
  

错误84类型或命名空间名称'FuncResultCode'不能   发现(您是否缺少using指令或程序集引用?)

应该将typeof(枚举)用于枚举吗?如果没有,那还有什么用?

1 个答案:

答案 0 :(得分:0)

您的代码应该可以正常工作,我编写了一个非常小的代码并且它正常工作。

using MyNamespace.something;
using System;

namespace ConsoleApplication1
{
class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(" " + typeof(FuncResultCode));
        Console.ReadLine();
    }
}

}

namespace MyNamespace.something
{
public enum FuncResultCode
{
    SUCCESS,
    MISSING_INFO,
    UNALLOWED_CHANGES
 }
}

输出符合预期:

enter image description here