Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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;
}
}
}