Share via


Enum.GetUnderlyingType メソッド

指定した列挙体の基になる型を返します。

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

パラメータ

  • enumType
    列挙型。

戻り値

enumType の基になる Type

例外

例外の種類 条件
ArgumentNullException enumType が null 参照 (Visual Basic では Nothing) です。
ArgumentException enumTypeEnum ではありません。

解説

GetUnderlyingType の使用方法については、次のコード例を参照してください。

 
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 );
}

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

Enum クラス | Enum メンバ | System 名前空間 | GetTypeCode