The first version converts a group of methods as part of matching "argument to parameter". This conversion is not performed for extension methods. The same is true for lambda expressions - you could not write:
((int x) = > x * 2).RunFunction(10);
or.
Section 7.6.5.2 of the C # 4 specification provides details about extension method calls. This begins by requiring the method to call one of the following forms:
expr.identifier ( ) expr.identifier ( args ) expr.identifier < typeargs > ( ) expr.identifier < typeargs > ( args )
This rule uses the expression type ( expr
):
The extension method C i .M j is eligible if
- [...]
- An implicit conversion of an identity, reference, or box exists from expr to the type of the first parameter M j .
An annotated version of the specification then includes this comment from Eric Lippert:
This rule ensures that the creation of a method that extends double
is not propagated by int
either. It also ensures that anonymity methods are not defined for anonymous functions or groups of methods.
source share