編譯器錯誤 CS0254
fixed 陳述式指派運算子的右邊不能是 cast 運算式
fixed 運算式的右邊不能使用 cast。 如需詳細資訊,請參閱 Unsafe 程式碼和指標。
下列範例會產生 CS0254:
C#
// 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);
}
}
}