0 out of 2 rated this helpful - Rate this topic

Type.BaseType Property

Gets the type from which the current Type directly inherits.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
public abstract Type BaseType { get; }

Property Value

Type: System.Type
The Type from which the current Type directly inherits, or null if the current Type represents the Object class or an interface.

Implements

_Type.BaseType

The base type is the type from which the current type directly inherits. Object is the only type that does not have a base type, therefore null is returned as the base type of Object.

Interfaces inherit from zero or more base interfaces; therefore, this property returns null if the Type object represents an interface. The base interfaces can be determined with GetInterfaces or FindInterfaces.

If the current Type represents a constructed generic type, the base type reflects the generic arguments. For example, consider the following declarations:

class B<U> { }
class C<T> : B<T> { }

For the constructed type C<int> (C(Of Integer) in Visual Basic), the BaseType property returns B<int>.

If the current Type represents a type parameter of a generic type definition, BaseType returns the class constraint, that is, the class the type parameter must inherit. If there is no class constraint, BaseType returns System.Object.

This property is read-only.

The following example demonstrates using the BaseType property.

using System;
class TestType 
{
    public static void Main() 
    {
        Type t = typeof(int);
        Console.WriteLine("{0} inherits from {1}.", t,t.BaseType);
    }
}


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
If current type is open generic type

If current type is open generic type (B) which derives from another open generic type (A) and this property does not return open generic type A. It returns constructed generic type A with parameters passed to A from B. Consider following:

Class A(Of TA1, TA2)
End Class
Class B(Of TB1, TB2) : Inherits A(Of TB1, TB2)
End Class

GetType(B(Of ,)).BaseType does not return open generic type A and GetType(B(Of ,)).BaseType.Equals(GetType(A(Of ,))) returns false. It is because Base type of open generic type B is not open generic type A, but constructed generic type A - something like A(Of TB1, TB2). This is correct behavior, but one may find it little puzzling. The behavior is correct because TB1 is not the same as TA1 (though in this example it may seem as if they are same). But TB1 may potentially have some constraint attached and in this case, TB1 is somethign completelly different than TA1. Or inheritance may be declared in even more complicated way like this:

Class C(Of TC1 As {New, IFormattable}, TC2) : Inherits A(Of Long, TC1)
End Class

In this case you can clearly see that base class of C is really not open generic type A - it is constructed generic type A(Of Long, TC1).