This is at least a question about how method overloading works in C #. I think you have identified an interesting situation here ...
In the first case (using the new keyword in the method), the compiler decides to use the Print method overload with a parameter of type C, because it is exactly equivalent to the parameter of the passed parameter (i.e., it does not require an implicit conversion), while I need an implicit conversion to the interface if the compiler has to choose the Print method, which takes an argument of type i - in other words, it chooses a more "obvious" method overload.
In the second case (using the override keyword in the method), the compiler decides to use the Print overload with a parameter of type I, because although you override the overload of the Print(C c) method in class B, it is effectively defined in the parent class A, which makes the Print(I i) method Print(I i) overload is actually the overload of the highest level and therefore the most direct, that is, the first one that the compiler finds.
Hope this helps you understand. Let me know if I need to attach any more items ...
Note. If I am mistaken in saying that the compiler does these things, then please correct me, although this does not really matter for the argument whether it looks like a compiler or CLR / JIT.
Noldorin Apr 02 '09 at 16:37 2009-04-02 16:37
source share