in .Net you can make your Enum inherit from sbyte, byte, short, ushort, int,
uint, long, ulong (default is int).
What I'm trying to do is determine what is the underlying type of a enum at
runtime via reflection. But I cant figure out how. If I get the Type of my
custom emun, it's base type property just says System.Enum, who's base type
is System.Enum (and on and on...).
Is there anyway to figure this out?
Thanks,
john conwell - 27 Nov 2007 19:14 GMT
Oh, never mind. I found it:
Enum.GetUnderlyingType(typeof(MyCustomEnum))
> in .Net you can make your Enum inherit from sbyte, byte, short, ushort, int,
> uint, long, ulong (default is int).
[quoted text clipped - 6 lines]
> Is there anyway to figure this out?
> Thanks,
Jon Skeet [C# MVP] - 27 Nov 2007 19:32 GMT
> in .Net you can make your Enum inherit from sbyte, byte, short, ushort, int,
> uint, long, ulong (default is int).
[quoted text clipped - 5 lines]
>
> Is there anyway to figure this out?
Use Enum.GetUnderlyingType(Type)

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk