编译器错误 CS1628
更新:2007 年 11 月
错误消息
不能在匿名方法、lambda 表达式或查询表达式内使用 ref 或 out 参数“parameter”
如果您在匿名方法块内使用 ref 或 out 参数,则会出现此错误。若要避免此错误,请使用局部变量或某个其他的构造。
下面的示例生成 CS1628:
// CS1628.cs
delegate int MyDelegate();
class C
{
public static void F(ref int i)
{
MyDelegate d = delegate { return i; }; // CS1628
// Try this instead:
// int tmp = i;
// MyDelegate d = delegate { return tmp; };
}
public static void Main()
{
}
}