Bro*_*ass 20
你在找Enum.GetUnderlyingType(enumType);
来自MSDN的示例:
static object GetAsUnderlyingType(Enum enval)
{
Type entype = enval.GetType();
Type undertype = Enum.GetUnderlyingType(entype);
return Convert.ChangeType(enval, undertype);
}
Run Code Online (Sandbox Code Playgroud)
using System;
class Program
{
enum IntEnum : int { A }
static void Main(string[] args)
{
var intEnum = IntEnum.A;
Console.WriteLine(intEnum.GetType().GetEnumUnderlyingType());
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
Run Code Online (Sandbox Code Playgroud)