Share via


Enum.GetUnderlyingType 方法

返回指定枚举的基础类型。

**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
<ComVisibleAttribute(True)> _
Public Shared Function GetUnderlyingType ( _
    enumType As Type _
) As Type
用法
Dim enumType As Type
Dim returnValue As Type

returnValue = Enum.GetUnderlyingType(enumType)
[ComVisibleAttribute(true)] 
public static Type GetUnderlyingType (
    Type enumType
)
[ComVisibleAttribute(true)] 
public:
static Type^ GetUnderlyingType (
    Type^ enumType
)
/** @attribute ComVisibleAttribute(true) */ 
public static Type GetUnderlyingType (
    Type enumType
)
ComVisibleAttribute(true) 
public static function GetUnderlyingType (
    enumType : Type
) : Type

参数

  • enumType
    枚举类型。

返回值

enumType 的基础 Type

异常

异常类型 条件

ArgumentNullException

enumType 为 空引用(在 Visual Basic 中为 Nothing)。

ArgumentException

enumType 不是 Enum

备注

下面的代码示例说明如何使用 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
static object GetAsUnderlyingType(Enum enval)
{
    Type entype = enval.GetType();

    Type undertype = Enum.GetUnderlyingType(entype);

    return Convert.ChangeType( enval, undertype );
}
Object^ GetAsUnderlyingType( Enum ^ enval )
{
   Console::WriteLine(  "GetAsUnderlying" );
   Type^ entype = enval->GetType();
   Type^ undertype = Enum::GetUnderlyingType( entype );
   return Convert::ChangeType( (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 );
}

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

Enum 结构
Enum 成员
System 命名空间
GetTypeCode