title: Set readonly fields in a constructor local function c#
body: <p>The following does not compile. </p>
  
  <pre><code>public class A
  {
      private readonly int i;
  
      public A()
      {
          void SetI()
          {
              i = 10; 
          }
  
          SetI();
      }
  }
  </code></pre>
  
  <p>It fails with this error:</p>
  
  <blockquote>
    <p>CS0191 A readonly field cannot be assigned to (except in a constructor or a variable initializer)</p>
  </blockquote>
  
  <p>Technically are we not in the constructor still, since the visibility of the local function is limited, so I'm wondering why this does not compile.</p>