This is because T
limited by Base
semantics. I cannot say exactly what happens with type binding at runtime, but this is my reasonable assumption.
You do not override the method properly, but instead hide it with "new", if you use a reference to the base class, you bypass any hiding. Here is a recession.
Members that hide other members are executed only if you use a link to the type in which they are hidden. You can always bypass the hidden element using the link to the base class:
var derived = new Derived(); var baseRef = (Base)derived; baseRef.Method();
To correctly override a method and use this code, mark the method as virtual
in the base class and override
in the derived class.
class Base { public virtual void Method() {} } class Derived : Base { public override void Method() {} }
You can prove it, change the general constraint to where T : Derived
, and it should fall into the "new" element.
source share