共用方式為


編譯器錯誤 CS0210

更新:2007 年 11 月

錯誤訊息

在 fixed 或 using 陳述式宣告中,您必須提供初始設定式

您必須在 fixed 陳述式中宣告和初始化該變數。如需詳細資訊,請參閱 Unsafe 程式碼和指標 (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");
      }
   }
}