【发布时间】:2014-01-02 13:38:28
【问题描述】:
从书中阅读这行代码示例:
Func<string,int> returnLength;
returnLength = delegate (string text) { return text.Length; };
Console.WriteLine(returnLength("Hello"));
上面写着
Func<string,double,int>等价于表单的委托类型public delegate int SomeDelegate(string arg1, double arg2)
所以Func 是代表?那么我们在代码示例中再次定义的那个委托是什么?
我们从Func 定义一个变量,就像delegate,然后将它再次分配给另一个delegate?我非常困惑,无法理解这个概念。 :(
谁能解释一下?
【问题讨论】:
-
Func 是一个具有某种返回类型的委托..
-
我在你的代码中看不到任何匿名类型。
-
@MarcinJuraszek:
returnLength被分配了一个匿名代表。 OP 很困惑,改用了“匿名type”这个词。 -
@Gabe 好的,我现在明白了。但要 100% 正确,他所指的东西称为 anonymous method,而不是 anonymous delegate。请参阅 MSDN:msdn.microsoft.com/en-us/library/0yw3tz5k.aspx