I would like to know if 'theObject' is an enum (of any enum type)
foreach (var item in Enum.GetValues(theObject.GetType())) { //do something }
In C#, we can check the specific type is enum or not by using the IsEnum property of the Type class. It will return true if the type is enum. Otherwise, this property will return false. It is a read-only property.
Enum types cannot be nullable.
The question is the answer. :)
bool isEnum = theObject is Enum;
If you have a Type
, use the Type.IsEnum
property, e.g.:
bool isEnum = theObject.GetType().IsEnum;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With