Get enum underlying type in CSharp

Description

The following code shows how to get enum underlying type.

Example


using System;//from   ww  w . jav  a  2s  . co m

enum EmpType : byte {
    Manager = 10,
    Grunt = 1,
    Contractor = 100,
    VP = 9
}

class Program {
    static void Main(string[] args) {
        EmpType fred;
        fred = EmpType.VP;

        Console.WriteLine(Enum.GetUnderlyingType(typeof(EmpType)));

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var