Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It follows the rules in section 7.5.3.2 of the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=dfbf523c-f98c-4804-afbd-459e846b268e&amp;displaylang=en" rel="nofollow noreferrer">C# 4 specification</a> ("Better function member").</p> <p>First (well, after seeing that both methods are <em>applicable</em>) we need to check the conversions from argument types to parameter types. In this case it's reasonably simple because there's only one argument. Neither conversion of argument type to parameter type is "better" because both are converting from <code>ConcreteA</code> to <code>IfaceA</code>. It therefore moves on to the next set of criteria, including this:</p> <blockquote> <p>Otherwise, if MP has more specific parameter types than MQ, then MP is better than MQ. Let {R1, R2, …, RN} and {S1, S2, …, SN} represent the uninstantiated and unexpanded parameter types of MP and MQ. MP’s parameter types are more specific than MQ’s if, for each parameter, RX is not less specific than SX, and, for at least one parameter, RX is more specific than SX:specific than SX:</p> <ul> <li>A type parameter is less specific than a non-type parameter.</li> <li>...</li> </ul> </blockquote> <p>So even though the <em>conversion</em> is equally good, the overload using <code>IfaceA</code> directly (rather than via delegates) is deemed "better" because a parameter of type <code>IfaceA</code> is more specific than a parameter of type <code>T</code>.</p> <p>There's no way of getting the compiler to warn on this behaviour - it's just normal overload resolution.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload