Check value type of extended class instance
I have
BaseClass
and MyClass : BaseClass
.
Using val is BaseClass
will return true for any object that is, or extends BaseClass
.
How can I check if the object is of type MyClass
, and not BaseClass
?8 Replies
val is MyClass
...?I want to make test2 return false
test2 is not BaseClass
thenAm I actually this dumb
I think maybe I'm just overthinking it lol
Any instance of a subtype is also an instance of the base class, that's not changeable and is just how inheritance works
So it's a bit unclear what you mean with "I want test2 to be false" - all MyClass instances are valid BaseClass instances
test2.GetType() == typeof(BaseClass)
I'm not sure why you want that, but that's how you do itI got it now. I was partially overthinking it, but I also didn't properly understand what I was trying to do. I got it now though :)
Just using is/is not