更新:2007 年 11 月
错误消息
无法将没有参数列表的匿名方法块转换为委托类型“delegate”,因为它有一个或多个 out 参数。
编译器允许在大多数情况下从匿名方法块中省略参数。当匿名方法块没有参数列表,而委托具有 out 参数时,会发生此错误。编译器不允许这种情况,因为它需要忽略 out 参数的存在,而这不可能是正确的行为。
示例
下面的代码生成错误 CS1688。
// CS1688.cs
using System;
delegate void OutParam(out int i);
class ErrorCS1676
{
static void Main()
{
OutParam o;
o = delegate // CS1688
// Try this instead:
// o = delegate(out int i)
{
Console.WriteLine("");
};
}
}