共用方式為


編譯器錯誤 CS0199

更新:2007 年 11 月

錯誤訊息

不能傳遞靜態唯讀欄位 'name' 的欄位給 ref 或 out (除非在靜態建構函式中)

readonly 變數的 static 用法必須與要以 refout 參數方式傳遞此變數的建構函式之用法相同。如需詳細資訊,請參閱傳遞參數 (C# 程式設計手冊)

範例

下列範例會產生 CS0199:

// CS0199.cs
class MyClass
{
    public static readonly int TestInt = 6;

    static void TestMethod(ref int testInt)
    {
        testInt = 0;
    }

    MyClass()
    {
        TestMethod(ref TestInt);   // CS0199, TestInt is static
    }

    public static void Main()
    {
    }
}