title: C# - For loop and the lambda expressions
body: <p>my question is why i'm getting wrong results using a iterator variable in a lambda expression.</p>
  
  <p>Well i've followed SWeko's answer <a href="https://stackoverflow.com/questions/3168375/using-the-iterator-variable-of-foreach-loop-in-a-lambda-expression-why-fails">here</a>. but it did not worked for me
  Here is my pseudo-code:</p>
  
  <pre><code>List&lt;string&gt; list = new List&lt;string&gt;(3);
  // where list.Count=3
  for (int i=0;i&lt;list.Count;i++){
      int yy=i;
      AFunctionWithLambda(() =&gt; Console.WriteLine (list[yy]));
  }
  </code></pre>
  
  <p>But the console only writes</p>
  
  <pre><code>list[3]
  </code></pre>
  
  <p>three times, as if the only value which "yy" could be is the last value of "i"
  It seemed to work because before declaring the "yy" variable, the Console returned "i=1" but it doesn't really, i don't know what i am mising.</p>
  
  <p>Thanks in advice!</p>