編譯器錯誤 CS0662
更新:2007 年 11 月
錯誤訊息
'method' 不能在 ref 參數上只指定 Out 屬性。請同時使用 In 與 Out 屬性,或都不使用。
介面方法有一個使用 ref 卻只有 Out 屬性 (Attribute) 的參數。使用 Out 屬性的 ref 參數也必須使用 In 屬性。
下列範例會產生 CS0662:
// CS0662.cs
using System.Runtime.InteropServices;
interface I
{
void method([Out] ref int i); // CS0662
// try one of the following lines instead
// void method(ref int i);
// void method([Out, In]ref int i);
}
class test
{
public static void Main()
{
}
}