C# Program to Check a Class is a Sub-Class of a Specified Class or Not
A class is a collection of methods, variables, and objects. A subclass is a class that is extended from the parent class. It should achieve all the properties from the parent class. Its syntax is similar to a class. Using: operator we can create the subclass. We can check the class is a subclass of the specific class or not by using the IsSubclassOf() method of the Type class. Or we can say that IsSubclassOf() method is used to check whether the current Type is derived from the given type. It will return true if the subclass is specific to the parent class. Otherwise, it will return false. This method will throw ArgumentNullException when the class name is null type. This method is used to:
- Check whether the class is derived from another class.
- Check whether a type is derived from the ValueType.
- Check whether the type is derived from Enum.
- Check whether a type is derived from the delegate.
public virtual bool IsSubclassOf(Type c);
True False False
Given class is a sub class