共用方式為


編譯器警告 (層級 1) CS0197

更新:2007 年 11 月

錯誤訊息

將 'argument' 當做 ref 或 out 傳遞或取得它的位址可能會導致執行階段例外狀況,因為它是 marshal-by-reference 類別的欄位

任何直接或間接從 MarshalByRefObject 衍生的類別都是 marshal-by-reference 類別。這種類別可為跨處理和機器界限參考的封送處理 (Marshal)。因此,這種類別的執行個體可以做為遠端物件的 Proxy。您無法將 Proxy 物件的欄位當做 refout 來傳遞。因此,您不能將這種類別的欄位當做 ref 或 out 傳遞,除非執行個體為 this,它不會是 Proxy 物件。

範例

下列範例會產生 CS0197。

// CS0197.cs
// compile with: /W:1
class X : System.MarshalByRefObject
{
   public int i;
}

class M
{
   public int i;
   static void AddSeventeen(ref int i)
   {
      i += 17;
   }

   static void Main()
   {
      X x = new X();
      x.i = 12;
      AddSeventeen(ref x.i);   // CS0197

      // OK
      M m = new M();
      m.i = 12;
      AddSeventeen(ref m.i);
   }
}