views:

79

answers:

3

I would like to know if 'theObject' is an enum (of any enum type)

 foreach (var item in Enum.GetValues(theObject.GetType())) {

     //do something
 }
+4  A: 

Use the Type.IsEnum property, e.g.:

bool isEnum = theObject.GetType().IsEnum;
Chris Schmich
+10  A: 

The question is the answer. :)

bool isEnum = theObject is Enum;
Evgeny
@Evgeny: I like it :)
Chris Schmich
Love it! And even closer to the question: if (theObject is Enum) {...}
Peter Lillevold
+1  A: 

just use

if (theObject is Enum)
 //is an enum
Laramie