编译器错误 CS0254
更新:2007 年 11 月
错误消息
固定语句赋值的右边不能是强制转换表达式
fixed 表达式的右边不可使用转换。有关更多信息,请参见不安全代码和指针(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);
}
}
}