为什么这个 C# 不进行类型检查?在此示例中,我尝试将类型的方法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";
}
}