How to convert from System.Enum to base integer?

If you don’t want to cast,

Convert.ToInt32()

could do the trick.

The direct cast (via (int)enumValue) is not possible. Note that this would also be “dangerous” since an enum can have different underlying types (int, long, byte…).

More formally: System.Enum has no direct inheritance relationship with Int32 (though both are ValueTypes), so the explicit cast cannot be correct within the type system

Leave a Comment