共用方式為


編譯器錯誤 CS0254

更新:2007 年 11 月

錯誤訊息

fixed 陳述式設定運算子的右邊不能是 cast 運算式

fixed 運算式的右邊不能使用轉型。如需詳細資訊,請參閱 Unsafe 程式碼和指標 (C# 程式設計手冊)

下列範例會產生 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);
      }
   }
}