I have a class, which has a bunch of subclasses that inherit from it. How can I test to see whether an object is an instance of that super class, and not of any of the derived classes?
Example:
I have a Vehicle class, and it has several classes that inherit from it, like Car, Motorcycle, Bicycle, Truck, etc.
Assuming this, how do I test to see if a Vehicle object is really of the class Vehicle, and not Car or Bicycle? (Since a Car and a Bicycle are in this case an instance of the Vehicle class, too.)
if (theObject.GetType() == typeof(Vehicle))
{
// it's really a Vehicle instance
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With