c# Generic overloaded method dispatching ambiguous -


I just dominated a situation where a method transmission was unclear and if someone could understand that the compiler ( .NET 4.0) .3031 9) Selecting the overload for calling

  Interface interface {interface interface B & lt; T & gt; {Add Zero (Efacea A); Add T (TT); } Class Concrete A: Ephesians {} class abstract base class & lt; T & gt; : Efesby & lt; T & gt; {Add Public Virtual T (TT) {...} Add Public Virtual Zero (FACA A) {...}} Category Convertible: Base Class B & L; Ephesians & gt; {// does not override one of the relevant methods} Zero code () {var concreteB = new concrete B (); // Add it to zero (ifaaaaaa) concrete B.Ed (new Concrete A ()) is called; }  

In any case, the compiler has not warned me or even why it compiles? Thank you very much for any reply.

this ("firstly (well, after seeing that both methods applied ) We have to check the conversion on parameter types from conversion types, in this case it is quite easy because there is only one argument. The conversion type in the argument type of argument type is neither "better" because both ConcreteAs are being converted from to IfaceA . Therefore, from the next of these parameters Otherwise, if the more typical parameter types of the MPs are compared to the MQ, the MP is better than the MQ. Let's {R1, R2,. .., RN} and {S1, S2, ..., SN} unbalanced and unexpected parameter types represent MP and MQ parameter types of MPs are more specific than MQ, if for each parameter, less than Rx SX Not specific, and at least one paragraph For Itr, SX SX is more specific: specific SX:

  • a type parameter is specific at a non-type parameter.
  • ...

Even if conversion is equally good, IfaceA The surcharge ("instead of delegates") using " is considered" better "because the type of type IfaceA is more specific than one parameter type T .

There is no way to warn the compiler of this behavior - this is just a normal surcharge resolution.


Comments