I have three classes: ClassA, ClassB, ClassC.
ClassC extends ClassB which in turn extends ClassA.
When I call GetType() from ClassA‘s constructor, .net is returning ClassC‘s type. I’m baffled because this is happening in code that has been working for a while and which I haven’t touch in a while. Was there a hotfix to .net that changed the behavior of GetType()? I doubt that. My only other thought is that this has something to do with xUnit, the testing framework I’m using?
It’s behaving exactly as it’s supposed to.
GetType()returns the actual type of the instance of the object, even if it’s a subclass (and it has always behaved this way).typeof(ClassA)on the other hand would always give you the type forClassA.