Type.BaseType 属性

获取当前 Type 直接从中继承的类型。

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

语法

声明
Public MustOverride ReadOnly Property BaseType As Type
用法
Dim instance As Type
Dim value As Type

value = instance.BaseType
public abstract Type BaseType { get; }
public:
virtual property Type^ BaseType {
    Type^ get () abstract;
}
/** @property */
public abstract Type get_BaseType ()
public abstract function get BaseType () : Type

属性值

当前的 Type 直接从中继承的 Type;或者如果当前的 Type 表示 Object 类或一个接口,则为 空引用(在 Visual Basic 中为 Nothing)。

备注

基类型是当前类型直接从中继承的类型。Object 是唯一没有基类型的类型,因此 空引用(在 Visual Basic 中为 Nothing) 作为 Object 的基类型返回。

接口从零个或多个基接口继承;因此,如果 Type 对象表示一个接口,则此属性返回 空引用(在 Visual Basic 中为 Nothing)。可以用 GetInterfacesFindInterfaces 确定基接口。

如果当前 Type 表示构造泛型类型,则基类型将反射泛型形参。例如,请考虑下列声明:

class B<U> { }
class C<T> : B<T> { }
Class B(Of U)
End Class
Class C(Of T)
    Inherits B(Of T)
End Class
generic<typename U> ref class B { };
generic<typename T> class C : B<T> { };

对于构造类型 C<int>(在 Visual Basic 中为 C(Of Integer)),BaseType 属性 (Property) 将返回 B<int>

如果当前 Type 表示泛型类型定义的类型形参,则 BaseType 将返回类约束,即类型形参所必需继承的类。如果没有这样的类约束,则 BaseType 将返回 System.Object

此属性 (Property) 为只读。

示例

下面的示例演示如何使用 BaseType 属性 (Property)。

Imports System

Class TestType
   
    Public Shared Sub Main()
        Dim t As Type = GetType(Integer)
        Console.WriteLine("{0} inherits from {1}.", t, t.BaseType)
    End Sub 'Main
End Class 'TestType
using System;
class TestType 
{
    public static void Main() 
    {
        Type t = typeof(int);
        Console.WriteLine("{0} inherits from {1}.", t,t.BaseType);
    }
}
using namespace System;
void main()
{
   Type^ t = int::typeid;
   Console::WriteLine( "{0} inherits from {1}.", t, t->BaseType );
}
import System.*;

class TestType
{
    public static void main(String[] args)
    {
        Type t = int.class.ToType();
        Console.WriteLine("{0} inherits from {1}.", t, t.get_BaseType());
    } //main
} //TestType

平台

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

请参见

参考

Type 类
Type 成员
System 命名空间
Object 类
GetInterfaces
FindInterfaces
UnderlyingSystemType
IsSubclassOf

其他资源

反射类型和泛型类型