Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Compiler Error CS1673 

Error Message

Anonymous methods inside structs cannot access instance members of 'this'. Consider copying 'this' to a local variable outside the anonymous method and using the local instead

The following sample generates 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()

Community Additions

© 2015 Microsoft