title: C# - Readonly properties and fields cannot be set in derived class constructors
body: <p>I have a class structure like the following</p>
  
  <pre><code>abstract class AMyAbstractClass {
      public readonly int MyReadonlyField;
      public int MyReadonlyProperty { get; }//read-only auto-property (syntactic sugar)
  }
  class MyConcreteClass : AMyAbstractClass {
      MyConcreteClass() {
          this.MyReadonlyField = 1;
          this.MyReadonlyProperty = 1;
      }
  }
  </code></pre>
  
  <p>Which throws compilation errors</p>
  
  <blockquote>
    <p>A readonly field cannot be assigned to (except in a constructor or a variable initializer)</p>
  </blockquote>
  
  <p>And</p>
  
  <blockquote>
    <p>Property or indexer 'AMyAbstractClass.MyReadonlyProperty cannot be assigned to -- it is read only</p>
  </blockquote>
  
  <p>Respectively.</p>
  
  <p>In the first case, the error message is erroneous, since it <em>is</em> being set in a constructor!</p>
  
  <hr>
  
  <p>I can come up with alternative ways to have immutable object properties, but why is this situation disallowed? What are good practices for this type of encapsulation?</p>