Export (0) Print
Expand All
Expand Minimize

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 (C# Programming Guide).

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);
      }
   }
}

Community Additions

ADD
Show:
© 2014 Microsoft