C# Test if an object is an Enum

Posted by Aran Mulholland on Stack Overflow See other posts from Stack Overflow or by Aran Mulholland
Published on 2010-05-27T06:00:01Z Indexed on 2010/05/27 6:01 UTC
Read the original article Hit count: 234

Filed under:
|
|

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

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

     //make sure we have all the enumeration values in the collection
     if (this.ValuesCollection.Contains(item)) { }
     else {
        this.ValuesCollection.Add(item);
     }

     Console.WriteLine(item.ToString());
     Console.WriteLine(item.GetType().ToString());
 }

© Stack Overflow or respective owner

Related posts about c#

Related posts about enums