Edit

Share via


Compiler Error CS0213

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.

Example

The following sample generates CS0213.

C#
// 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;  
      }  
   }  
}