共用方式為


編譯器錯誤 CS1628

更新:2007 年 11 月

錯誤訊息

無法在匿名方法、Lambda 運算式或查詢運算式內使用 ref 或 out 參數 'parameter'。

如果您在匿名方法區塊內部使用 ref 或 out 參數,便會發生這個錯誤。若要避免這個錯誤,請使用區域變數或其他建構。

下列範例會產生 CS1628:

// CS1628.cs

delegate int MyDelegate();

class C
{
  public static void F(ref int i)
  {
      MyDelegate d = delegate { return i; };  // CS1628
      // Try this instead:
      // int tmp = i;
      // MyDelegate d = delegate { return tmp; };
  }

  public static void Main()
  {
     
  }
}