Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Fields of static readonly field 'name' cannot be passed ref or out (except in a static 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()
{
}
}