title: In C#, why can't an anonymous method contain a yield statement?
body: <p>I thought it would be nice to do something like this (with the lambda doing a yield return):</p>
  
  <pre><code>public IList&lt;T&gt; Find&lt;T&gt;(Expression&lt;Func&lt;T, bool&gt;&gt; expression) where T : class, new()
  {
      IList&lt;T&gt; list = GetList&lt;T&gt;();
      var fun = expression.Compile();
  
      var items = () =&gt; {
          foreach (var item in list)
              if (fun.Invoke(item))
                  yield return item; // This is not allowed by C#
      }
  
      return items.ToList();
  }
  </code></pre>
  
  <p>However, I found out that I can't use yield in anonymous method.  I'm wondering why.  The <a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx" rel="noreferrer">yield docs</a> just say it is not allowed.</p>
  
  <p>Since it wasn't allowed I just created List and added the items to it. </p>