Enabling method overloading in C # does not always behave as you might expect, but your code behaves according to the specification (I wrote a blog post about this a while ago).
In short, the compiler begins by looking for methods that
- Has the same name (in your case
Test ) - are declared in type (in your case
B ) or one of its base types - not declared using override modifier
Please note that the last point. This is actually logical, since virtual methods are resolved at runtime, not compilation time.
Finally, if the type (in this case B ) has a method that is a candidate (which means that the parameters in your call can be implicitly converted to the parameter type of the candidate method), this method will be used. Your overridden method is not even part of the decision-making process.
If you want to call your overridden method, you need to first transfer the object to its base type.
Fredrik Mörk
source share