为什么我不能只传递一个预期类似类型的Func的方法的名称?

Dav*_*gel 4 c# mono gmcs

为什么不用这个C#typecheck?在这个例子中,我试图传递一个类型的方法string -> string作为Func<string, string>.在传递适当类型的函数的名称时,能够省略lambda语法似乎是完全合理的.

using System;
using System.Linq;

class WeakInference
{
  public static void Main (string [] args)
  {
    // doesn't typecheck
    var hellos = args.Select (AppendHello); 

    // have to do this:
    // var hellos = args.Select (s => AppendHello (s));
  }

  static string AppendHello (string s)
  {
    return s + "hello";
  }
}
Run Code Online (Sandbox Code Playgroud)

Jon*_*eet 6

您可以使用C#4编译器.C#3编译器在方法组转换方面的类型推断较弱.您可以在此处阅读Eric Lippert的答案中的详细信息.我不完全清楚这是否意味着C#3编译器实际上没有实现C#3规范,或者规范本身是否在这个区域中在3和4之间变化.与编译器是否符合您的要求相比,这是一个非常学术性的问题;)

(我刚测试过,你的程序不能用VS 2008编译,但是用VS 2010编译.)