Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0213 

Error Message

You cannot use the fixed statement to take the address of an already fixed expression

A local variable in an unsafe method or a parameter is already fixed (on the stack), so you cannot take the address of either of these two variables in a fixed expression. For more information, see Unsafe Code and Pointers (C# Programming Guide).

Example

The following sample generates CS0213.

// CS0213.cs
// compile with: /unsafe
public class MyClass
{
   unsafe public static void Main()
   {
      int i = 45;
      fixed (int *j = &i) { }  // CS0213
      // try the following line instead
      // int* j = &i;

      int[] a = new int[] {1,2,3};
      fixed (int *b = a)
      {
         fixed (int *c = b) { }  // CS0213
         // try the following line instead
         // int *c = b;
      }
   }
}

Community Additions

ADD
Show:
© 2014 Microsoft