Compiler Error CS0254
The right hand side of a fixed statement assignment may not be a cast expression
The right side of a fixed expression may not use a cast. For more information, see Unsafe Code and Pointers.
The following sample generates CS0254:
// CS0254.cs
// compile with: /unsafe
class Point
{
public uint x, y;
}
class FixedTest
{
unsafe static void SquarePtrParam (int* p)
{
*p *= *p;
}
unsafe public static void Main()
{
Point pt = new Point();
pt.x = 5;
pt.y = 6;
fixed (int* p = (int*)&pt.x) // CS0254
// try the following line instead
// fixed (uint* p = &pt.x)
{
SquarePtrParam ((int*)p);
}
}
}
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: