我想知道“ theObject”是否为枚举(任何枚举类型)
foreach (var item in Enum.GetValues(theObject.GetType())) {
//do something
}
我想知道“ theObject”是否为枚举(任何枚举类型)
foreach (var item in Enum.GetValues(theObject.GetType())) {
//do something
}
Answers:
问题是答案。:)
bool isEnum = theObject is Enum;
如果您有Type
,请使用Type.IsEnum
属性,例如:
bool isEnum = theObject.GetType().IsEnum;
Type
枚举类型。+1