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
Angius9mo ago
val is MyClass...?
UnemployedNinja
UnemployedNinjaOP9mo ago
No description
UnemployedNinja
UnemployedNinjaOP9mo ago
I want to make test2 return false
Angius
Angius9mo ago
test2 is not BaseClass then
UnemployedNinja
UnemployedNinjaOP9mo ago
Am I actually this dumb I think maybe I'm just overthinking it lol
Pobiega
Pobiega9mo 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
Aaron9mo ago
test2.GetType() == typeof(BaseClass) I'm not sure why you want that, but that's how you do it
UnemployedNinja
UnemployedNinjaOP9mo 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
Want results from more Discord servers?
Add your server