Assembly: mscorlib (in mscorlib.dll)
<ComVisibleAttribute(True)> _
Public Overridable Function IsSubclassOf ( _
c As Type _
) As Boolean[ComVisibleAttribute(true)]
public virtual bool IsSubclassOf(
Type c
)[ComVisibleAttribute(true)]
public:
virtual bool IsSubclassOf(
Type^ c
)[<ComVisibleAttribute(true)>]
abstract IsSubclassOf :
c:Type -> bool
[<ComVisibleAttribute(true)>]
override IsSubclassOf :
c:Type -> bool Parameters
- c
- Type: System
. . :: . Type
The type to compare with the current type.
Return Value
Type: Systemtrue 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.
Implements
_Type| Exception | Condition |
|---|---|
| ArgumentNullException | The c parameter is |
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
Note |
|---|
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
using System;
public class Class1 { }
public class DerivedC1 : Class1 { }
class IsSubclassTest
{
public static void Main()
{
Class1 myClass = new Class1();
DerivedC1 myDClass = new DerivedC1();
Type myClassType = myClass.GetType();
Type myDClassType = myDClass.GetType();
// Returns true:
Console.WriteLine("myDClass subclass of myClass: {0}", myDClassType.IsSubclassOf(myClassType));
Console.ReadLine();
}
}
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note