title: Is modifying a value type from within a using statement undefined behavior?
body: <p>This one's really an offshoot of <a href="https://stackoverflow.com/questions/4642665/why-does-capturing-a-mutable-struct-variable-inside-a-closure-within-a-using-stat">this question</a>, but I think it deserves its own answer.</p>
  
  <p>According to section 15.13 of the ECMA-334 (on the <code>using</code> statement, below referred to as <em>resource-acquisition</em>):</p>
  
  <blockquote>
    <p>Local variables declared in a
    <em>resource-acquisition</em> are read-only, and shall include an initializer. A
    compile-time error occurs if the
    embedded statement attempts to modify
    these local variables (via assignment
    or the <code>++</code> and <code>--</code> operators) or
    pass them as <code>ref</code> or <code>out</code>
    parameters.</p>
  </blockquote>
  
  <p>This seems to explain why the code below is illegal.</p>
  
  <pre><code>struct Mutable : IDisposable
  {
      public int Field;
      public void SetField(int value) { Field = value; }
      public void Dispose() { }
  }
  
  using (var m = new Mutable())
  {
      // This results in a compiler error.
      m.Field = 10;
  }
  </code></pre>
  
  <p>But what about this?</p>
  
  <pre><code>using (var e = new Mutable())
  {
      // This is doing exactly the same thing, but it compiles and runs just fine.
      e.SetField(10);
  }
  </code></pre>
  
  <p><strong>Is the above snippet undefined and/or illegal in C#?</strong> If it's legal, what is the relationship between this code and the excerpt from the spec above? If it's <em>illegal</em>, why does it work? Is there some subtle loophole that permits it, or is the fact that it works attributable only to mere luck (so that one shouldn't ever rely on the functionality of such seemingly harmless-looking code)?</p>