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.
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;
}
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback: