ewalt

ewalt

  • NA
  • 5
  • 0

Casting en enum to its underlying type.

Feb 2 2005 9:50 PM
Hey, this is kind of an obscure question... How do I cast (convert) an Enum of arbitrary type to its underlying type? I have a method that gets passed an Enum object (I don't know what type, other than it is an Enum), and the method needs to somehow convert that to an object of its underlying type. Thus, if it were passed en Enum whose type was byte and whose value was 5, then it would need to return a byte whose value was 5. If this is impossible, then how do I tell what the underlying type of an Enum is? Enum.GetType().GetElementType() does NOT work. Thanks for any help!

Answers (7)