Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0199 

Error Message

A static readonly field cannot be passed ref or out (except in a static constructor)

A readonly variable must have the same static usage as the constructor in which you want to pass it as a ref or out parameter. For more information, see Passing Parameters (C# Programming Guide).

Example

The following sample generates 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()
    {
    }
}

Community Additions

ADD
Show:
© 2015 Microsoft