This documentation is archived and is not being maintained.

Type.IsSubclassOf Method

Determines whether the class represented by the current Type derives from the class represented by the specified Type.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

'Declaration
<ComVisibleAttribute(True)> _
Public Overridable Function IsSubclassOf ( _
	c As Type _
) As Boolean
'Usage
Dim instance As Type
Dim c As Type
Dim returnValue As Boolean

returnValue = instance.IsSubclassOf(c)
/** @attribute ComVisibleAttribute(true) */ 
public boolean IsSubclassOf (
	Type c
)
ComVisibleAttribute(true) 
public function IsSubclassOf (
	c : Type
) : boolean
Not applicable.

Parameters

c

The Type to compare with the current Type.

Return Value

true if the Type represented by the c parameter and the current Type represent classes, and the class represented by the current Type derives from the class represented by c; otherwise, false. This method also returns false if c and the current Type represent the same class.

Exception typeCondition

ArgumentNullException

The c parameter is a null reference (Nothing in Visual Basic).

The IsSubclassOf method cannot be used to determine whether an interface derives from another interface, or whether a class implements an interface. Use the GetInterface method for that purpose. Note that if a type is dervived from an interface, this method returns true for that type being a subclass of Object.

If the current Type represents a type parameter in the definition of a generic type or generic method, it derives from its class constraint or from System.Object if it has no class constraint.

NoteNote:

If the IsSubclassOf is the converse of IsAssignableFrom. That is, if t1.IsSubclassOf(t2) is true, then t2.IsAssignableFrom(t1) is also true.

This method can be overridden by a derived class.

The following example demonstrates the use of the IsSubclassOf method by creating an instance of a class and an instance of its derived class.

Imports System

Public Class Class1
End Class

Public Class DerivedC1
    Inherits Class1
End Class

Class IsSubclassTest

    Public Shared Sub Main()
        Dim myC1 As Class1 = New Class1
        Dim myDClass As DerivedC1 = New DerivedC1
        Dim myClassType As Type = myC1.GetType
        Dim myDClassType As Type = myDClass.GetType

        ' Returns true:
        Console.WriteLine("myDClass subclass of myClass: {0}", myDClassType.IsSubclassOf(myClassType))
        Console.ReadLine()
    End Sub
End Class

Windows 98, Windows Server 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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Show: