コンパイラ エラー CS1673

更新 : 2007 年 11 月

エラー メッセージ

構造体内部の匿名メソッド、ラムダ式、またはクエリ式は、'this' のインスタンス メンバにアクセスできません。'this' を匿名メソッド、ラムダ式、またはクエリ式の外部のローカル変数にコピーして、そのローカルを使用してください。

次の例では 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()
   {
   }
}