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