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.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for