Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0199

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.

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()
   {
   }
}

Show:
© 2014 Microsoft