Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Compiler Error CS0198
Collapse the table of content
Expand the table of content

Compiler Error CS0198

A static readonly field cannot be assigned to (except in a static constructor or a variable initializer)

A readonly variable must have the same static usage as the constructor in which you want to initialize it.

The following sample generates CS0198:

// CS0198.cs
class MyClass
{
   public static readonly int TestInt = 6;

   MyClass()
   {
      TestInt = 11;   // CS0198, constructor is not static and readonly field is
   }

   public static void Main()
   {
   }
}
Show:
© 2015 Microsoft