I am wondering why the C# 3.0 compiler is unable to infer the type of a method when it is passed as a parameter to a generic function when it can implicitly create a delegat
Maybe this will make it clearer:
public class SomeClass
{
static void foo(int x) { }
static void foo(string s) { }
static void bar(Action f){}
static void barz(Action f) { }
static void test()
{
Action f = foo;
bar(f);
barz(foo);
bar(foo);
//these help the compiler to know which types to use
bar(foo);
bar( (int i) => foo(i));
}
}
foo is not an action - foo is a method group.
Edit: I've added two (more) ways to help the compiler figure out the type (ie - how to skip the inference steps).
From my reading of the article in JSkeet's answer, the decision to not infer the type seems to be based on a mutual infering scenario, such as
static void foo(T x) { }
static void bar(Action f) { }
static void test()
{
bar(foo); //wut's T?
}
Since the general problem was unsolve-able, they choose to left specific problems where a solution exists as unsolved.
As a consequence of this decision, you won't be adding a overload for a method and getting a whole lot of type confusion from all the callers that are used to a single member method group. I guess that's a good thing.