检查枚举类型是否为ulong

时间:2013-02-13 23:01:29

标签: c# types

我有一个枚举,我想检查枚举类型是否为ulong。

到目前为止尝试过:

 var checkValue = Enum.GetUnderlyingType(param.ParamType); // param is enum
 if (checkValue is ulong){ } // doesn't work

 var checkValue = param.value;
 if (checkValue is ulong){ } // doesn't work

任何想法?

2 个答案:

答案 0 :(得分:9)

Enum.GetUnderlyingType会返回Type类型的对象,因此它确实不是ulong,它本身就是ulong类型:)

试试这个:

if (checkValue == typeof(ulong))

答案 1 :(得分:0)

试试这个:

var enumType = param.GetType();

var utype = Enum.GetUnderlyingType(entype);

if(utype == typeof(ulong))
相关问题