title: Lambda variable capture in loop - what happens here?
body: <p>I am trying to get  my head around, what happens here ? What sort of code does the compiler produce?</p>
  
  <pre><code>public static void vc()
  {
      var listActions = new List&lt;Action&gt;();
  
      foreach (int i in Enumerable.Range(1, 10))
      {
          listActions.Add(() =&gt; Console.WriteLine(i));
      }
  
      foreach (Action action in listActions)
      {
          action();
      }
  }
  
  static void Main(string[] args)
  { 
    vc();
  }
  </code></pre>
  
  <p><em>output:</em> 
  10
  10
  .. 
  10</p>
  
  <p>According to <a href="https://stackoverflow.com/questions/5438307/detailed-explanation-of-variable-capture-in-closures">this</a>, a new instance of ActionHelper would be created for every iteration. So in that case, I would assume it should print 1..10.
  Can someone give me some pseudo code of what the compiler is doing here ?</p>
  
  <p>Thanks.</p>