






















Ayende在使用.Net 3.0的时候遇到了这样一个问题Csc.exe and delegate inference, or: Why C# has awkward syntax
public class TestCsc
{
public static void TestMethod()
{
Execute(Bar); // fail to compile
Execute(delegate(int ia, string x) { }); // compiles fine
Execute((int i, string x) => { return; }); // Compiles fine
Execute((int i, string x) => { return true; }); // fail to compile
Execute(Foo);// fail to compile
Execute(delegate(int ia, string x) { return true; }); // fail to compile
} public static bool Foo(int ia, string x)
{
return false;
} public static void Bar(int ia, string x)
{
} public static void Execute<T, K>(Action<T, K> e)
{
} public static void Execute<T, K>(Func<bool, T, K> e)
{
}
}
失败的原因是什么呢??
Eric Lippert在他的blogFabulous Adventures In Coding 中给出了他的解释.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。