共用方式為


編譯器錯誤 CS1655

更新:2007 年 11 月

錯誤訊息

無法將 'variable' 的欄位當做 ref 或 out 引數傳遞,因為它是 'readonly variable type'

如果您嘗試將 foreach 變數、using 變數或 fixed 變數的成員當做 ref 或 out 引數傳遞至函式,便會發生這個錯誤。因為這些變數在這些內容中視為唯讀,所以不允許這樣做。

下列範例會產生 CS1655:

// CS1655.cs
struct S 
{
   public int i;
}

class CMain
{
  static void f(ref int iref)
  {
  }
  
  public static void Main()
  {
     S[] sa = new S[10];
     foreach(S s in sa)
     {
        CMain.f(ref s.i);  // CS1655
     }
  }
}