C# Type IsSubclassOf
Description
Type IsSubclassOf
determines whether the class represented
by the current Type derives from the class represented by the specified Type.
Syntax
Type.IsSubclassOf
has the following syntax.
[ComVisibleAttribute(true)]
public virtual bool IsSubclassOf(
Type c
)
Parameters
Type.IsSubclassOf
has the following parameters.
c
- The type to compare with the current type.
Returns
Type.IsSubclassOf
method returns 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.
Example
The following example demonstrates the use of the IsSubclassOf method by creating an instance of a class and an instance of its derived class.
/*from www. j a va2 s .c o m*/
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();
Console.WriteLine(myDClassType.IsSubclassOf(myClassType));
}
}
The code above generates the following result.