This documentation is archived and is not being maintained.

Compiler Error CS1686 

Error Message

Local 'variable' or its members cannot have their address taken and be used inside an anonymous method block

This error is generated when you use a variable, and attempt to take its address, and one of these actions is done inside an anonymous method.


The following sample generates CS1686.

// CS1686.cs
// compile with: /unsafe /target:library
class MyClass
   public unsafe delegate int * MyDelegate();

   public unsafe int * Test()
      int j = 0;
      MyDelegate d = delegate { return &j; };   // CS1686
      return &j;   // OK