This documentation is archived and is not being maintained.

Enum.GetUnderlyingType Method

Returns the underlying type of the specified enumeration.

[Visual Basic]
Public Shared Function GetUnderlyingType( _
   ByVal enumType As Type _
) As Type
public static Type GetUnderlyingType(
 Type enumType
public: static Type* GetUnderlyingType(
 Type* enumType
public static function GetUnderlyingType(
   enumType : Type
) : Type;


An enumeration type.

Return Value

The underlying Type of enumType.


Exception Type Condition
ArgumentNullException enumType is a null reference (Nothing in Visual Basic).
ArgumentException enumType is not an Enum.


The following code sample illustrates the use of GetUnderlyingType:

[Visual Basic] 
Shared Function GetAsUnderlyingType(enval As [Enum]) As Object
   Dim entype As Type = enval.GetType()
   Dim undertype As Type = [Enum].GetUnderlyingType(entype)
   Return Convert.ChangeType(enval, undertype)
End Function

static object GetAsUnderlyingType(Enum enval)
    Type entype = enval.GetType();

    Type undertype = Enum.GetUnderlyingType(entype);

    return Convert.ChangeType( enval, undertype );

Object* GetAsUnderlyingType(Enum* enval)
    Type* entype = enval->GetType();
    Type* undertype = Enum::GetUnderlyingType(entype);
    return Convert::ChangeType( dynamic_cast<Object*>(enval), undertype );

static function GetAsUnderlyingType(enval : Enum) : Object
    var entype : Type = enval.GetType();

    var undertype : Type = Enum.GetUnderlyingType(entype);

    return Convert.ChangeType( enval, undertype );


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Enum Class | Enum Members | System Namespace | GetTypeCode