Why is a generic method chosen when a non-generic exists?
According to the MSDN docs, priority is given to method signatures that are not overridden. Since the non-generic version of Foo is overridden, it immediately goes to the bottom of the priority of choosing a method. In general terms, the next step is to choose the most specific method possible and execute it. In the case of the Bar methods, the Bar(Baz baz)
method will always be the most specific in your case.
Overload resolution is a compile-time mechanism for selecting the best function member to invoke given an argument list and a set of candidate function members. Overload resolution selects the function member to invoke in the following distinct contexts within C#:
- Invocation of a method named in an invocation-expression (Section 7.5.5). Invocation of an instance constructor named in an object-creation-expression (Section 7.5.10.1).
- Invocation of an indexer accessor through an element-access (Section 7.5.6). Invocation of a predefined or user-defined operator referenced in an expression (Section 7.2.3 and Section 7.2.4).
Each of these contexts defines the set of candidate function members and the list of arguments in its own unique way, as described in detail in the sections listed above. For example, the set of candidates for a method invocation does not include methods marked override (Section 7.3), and methods in a base class are not candidates if any method in a derived class is applicable (Section 7.5.5.1).
MSDN Overload Resolution
I bolded the text that I think relates to your question.
Here's another question on Stack Overflow that might help out. It talks about method resolution in general. Doesn't touch on overridden methods, but helps fill in some of the process that I didn't touch on.