Export (0) Print
Expand All

Enum.GetUnderlyingType Method

Returns the underlying type of the specified enumeration.

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

Parameters

enumType
An enumeration type.

Return Value

The underlying Type of enumType.

Exceptions

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

Remarks

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

[C#] 
static object GetAsUnderlyingType(Enum enval)
{
    Type entype = enval.GetType();

    Type undertype = Enum.GetUnderlyingType(entype);

    return Convert.ChangeType( enval, undertype );
}

[C++] 
Object* GetAsUnderlyingType(Enum* enval)
{
    Console::WriteLine("GetAsUnderlying");
    Type* entype = enval->GetType();
    Type* undertype = Enum::GetUnderlyingType(entype);
    return Convert::ChangeType( dynamic_cast<Object*>(enval), undertype );
}

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

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

    return Convert.ChangeType( enval, undertype );
}

Requirements

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

Show:
© 2014 Microsoft