更新:2007 年 11 月

错误消息

必须在 fixed 或者 using 语句声明中提供初始值设定项

必须在 fixed 语句中声明并初始化变量。有关更多信息,请参见不安全代码和指针(C# 编程指南)

下面的示例生成 CS0210:

 复制代码
// CS0210a.cs
// compile with: /unsafe

class Point
{
   public int x, y;
}

public class MyClass
{
   unsafe public static void Main()
   {
      Point pt = new Point();

      fixed (int i)    // CS0210
      {
      }
      // try the following lines instead
      /*
      fixed (int* p = &pt.x)
      {
      }
      fixed (int* q = &pt.y)
      {
      }
      */
   }
}

下面的示例也生成 CS0210,因为 using 语句没有初始值设定项。

 复制代码
// CS0210b.cs

using System.IO;
class Test 
{
   static void Main() 
   {
      using (StreamWriter w) // CS0210
      // Try this line instead:
      // using (StreamWriter w = new StreamWriter("TestFile.txt")) 
      {
         w.WriteLine("Hello there");
      }
   }
}