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.
The following sample generates CS0192:
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() { } }
You can also get CS0192 if the readonly field is static and the constructor is not marked static.