title: Why i can't use yield return on lambda expressions
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1217729/in-c-why-cant-an-anonymous-method-contain-a-yield-statement">In C#, why can&#39;t an anonymous method contain a yield statement?</a>  </p>
  </blockquote>
  
  
  
  <p>I have this code:</p>
  
  <pre><code>Func&lt;IEnumerable&lt;int&gt;&gt; allNumbers = ()=&gt; new []{1,2,3};
  foreach (var number in allNumbers())
    Console.WriteLine(number);
  </code></pre>
  
  <p>But i would like (and has sense) to do somthing like this:</p>
  
  <pre><code>int i = 0;
  Func&lt;IEnumerable&lt;int&gt;&gt; allNumbers = () =&gt; {yield return ++i;};
  foreach (var number in allNumbers())
     Console.WriteLine(number);
  </code></pre>
  
  <p>and i get this compile error:
  "The yield statement cannot be used inside an anonymous method or lambda expression"</p>
  
  <p>So why i can't use yield returns (lazy things) inside c# lambda expressions?</p>