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
Angius
Angius4mo ago
val is MyClass...?
UnemployedNinja
UnemployedNinja4mo ago
No description
UnemployedNinja
UnemployedNinja4mo ago
I want to make test2 return false
Angius
Angius4mo ago
test2 is not BaseClass then
UnemployedNinja
UnemployedNinja4mo ago
Am I actually this dumb I think maybe I'm just overthinking it lol
Pobiega
Pobiega4mo ago
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
Aaron
Aaron4mo ago
test2.GetType() == typeof(BaseClass) I'm not sure why you want that, but that's how you do it
UnemployedNinja
UnemployedNinja4mo ago
I 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