Type.BaseType Property
Gets the type from which the current Type directly inherits.
Assembly: mscorlib (in mscorlib.dll)
Property Value
Type: System.TypeThe Type from which the current Type directly inherits, or null if the current Type represents the Object class or an interface.
Implements
_Type.BaseTypeThe 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:
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 uses recursion to list the complete inheritance hierarchy of each class found in an assembly. The example defines a class named C that derives from a class named B, which, in turn, derives from a class named A.
Public Class Example Public Shared Sub Main() For Each t In GetType(Example).Assembly.GetTypes() Console.WriteLine("{0} derived from: ", t.FullName) Dim derived As Type = t Do derived = derived.BaseType If derived IsNot Nothing Then Console.WriteLine(" {0}", derived.FullName) End If Loop While derived IsNot Nothing Console.WriteLine() Next End Sub End Class Public Class A End Class Public Class B : Inherits A End Class Public Class C : Inherits B End Class ' The example displays the following output: ' Example derived from: ' System.Object ' ' A derived from: ' System.Object ' ' B derived from: ' A ' System.Object ' ' C derived from: ' B ' A ' System.Object
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0