title: How closure in c# works when using lambda expressions?
body: <p>In to following tutorial : <a href="http://www.albahari.com/threading/" rel="noreferrer">http://www.albahari.com/threading/</a></p>
  
  <p>They say that the following code : </p>
  
  <pre><code>for (int i = 0; i &lt; 10; i++)
    new Thread (() =&gt; Console.Write (i)).Start();
  </code></pre>
  
  <p>is non deterministic and can produce the following answer : </p>
  
  <blockquote>
    <p>0223557799</p>
  </blockquote>
  
  <p>I thought that when one uses lambda expressions the compiler creates some kind of anonymous class that captures the variables that are in use by creating members like them in the capturing class.
  But <code>i</code> is value type, so i thought that he should be copied by value.</p>
  
  <p>where is my mistake ? </p>
  
  <p>It will be very helpful if the answer will explain how does closure work, how do it hold a "pointer" to a specific int , what code does generated in this specific case ?</p>