我想知道‘ theObject’是否是枚举(任何枚举类型)
foreach (var item in Enum.GetValues(theObject.GetType())) { //do something }
If you have a Type, use the Type.IsEnum property, e.g.:
Type
Type.IsEnum
bool isEnum = theObject.GetType().IsEnum;
The question is the answer. :)
bool isEnum = theObject is Enum;
just use
if (theObject is Enum) //is an enum
For generic type parameters, the parameter can be constrained rather than tested:
where T : Enum