编译器错误 CS1673
更新:2007 年 11 月
错误消息
结构内部的匿名方法、lambda 表达式和查询表达式无法访问“this”的实例成员。请考虑将“this”复制到匿名方法、lambda 表达式或查询表达式外部的某个局部变量并改用该局部变量。
下面的示例生成 CS1673:
// CS1673.cs
delegate int MyDelegate();
public struct S
{
int member;
public int F(int i)
{
member = i;
// Try assigning to a local variable
// S s = this;
MyDelegate d = delegate()
{
i = this.member; // CS1673
// And use the local variable instead of "this"
// i = s.member;
return i;
};
return d();
}
}
class CMain
{
public static void Main()
{
}
}