title: C#: yield return within a foreach fails - body cannot be an iterator block
body: <p>Consider this bit of obfuscated code. The intention is to create a new object on the fly via the anonymous constructor and <code>yield return</code> it. The goal is to avoid having to maintain a local collection just to simply <code>return</code> it.</p>
  
  <pre><code>public static List&lt;DesktopComputer&gt; BuildComputerAssets()
  {           
      List&lt;string&gt; idTags = GetComputerIdTags();
  
      foreach (var pcTag in idTags)
      {
          yield return new DesktopComputer() {AssetTag= pcTag
                                            , Description = "PC " + pcTag
                                            , AcquireDate = DateTime.Now
                                             };
      }            
  }
  </code></pre>
  
  <p>Unfortunately, this bit of code produces an exception:</p>
  
  <blockquote>
    <p>Error 28  The body of 'Foo.BuildComputerAssets()' cannot be an iterator block because 'System.Collections.Generic.List' is not an iterator interface type</p>
  </blockquote>
  
  <p><strong>Questions</strong></p>
  
  <ul>
  <li>What does this error message mean?</li>
  <li>How can I avoid this error and use <code>yield return</code> properly?</li>
  </ul>