NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Compiler Error CS0191

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

A readonly field can only take an assignment in a constructor or at declaration.

The following sample generates CS0191:

class MyClass {
   public readonly int TestInt = 6;  // OK to assign to readonly field in declaration

   MyClass() {
      TestInt = 11;  // OK to assign to readonly field in constructor
   }

   public void TestReadOnly() {
      TestInt = 19;  // CS0191
   }
   public static void Main() {
   }
}

You can also get CS0191 if the readonly field is static and the constructor is not marked static.