Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0192 

Error Message

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

A field (variable) marked with the readonly keyword cannot be passed either to a ref or out parameter except inside a constructor. For more information, see Fields (C# Programming Guide).

CS0192 also results if the readonly field is static and the constructor is not marked static.

Example

The following sample generates CS0192.

// CS0192.cs
class MyClass
{
    public readonly int TestInt = 6;
    static void TestMethod(ref int testInt)
    {
        testInt = 0;
    }

    MyClass()
    {
        TestMethod(ref TestInt);   // OK
    }

    public void PassReadOnlyRef()
    {
        TestMethod(ref TestInt);   // CS0192
    }

    public static void Main()
    {
    }
}

Community Additions

ADD
Show:
© 2014 Microsoft