Get the underlying type of the specified enumeration in CSharp
Description
The following code shows how to get the underlying type of the specified enumeration.
Example
using System;// www .j av a2 s .c o m
public class Example
{
public static void Main()
{
Enum[] enumValues = { ConsoleColor.Red, DayOfWeek.Monday,
MidpointRounding.ToEven, PlatformID.Win32NT,
DateTimeKind.Utc, StringComparison.Ordinal };
foreach (var enumValue in enumValues){
Type enumType = enumValue.GetType();
Type underlyingType = Enum.GetUnderlyingType(enumType);
Console.WriteLine("{0,-10} {1, 18} {2,15}",
enumValue, enumType.Name, underlyingType.Name);
}
}
}
The code above generates the following result.