I am trying to pass a an inherited class type in to a method and want to check if the type is a type of base class. How can I do this, since inherited.GetType() == typeof(baseclass) will return false?
The is
operator does this.
if (inherited is baseclass)
{
// do stuff
}
You could also use Type.BaseType
if you want to know that it is exactly the direct parent.
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