title: How To Use Yield Inside A Linq Query
body: <p>I have the following method:</p>
  
  <pre><code>    public string GetDepartmentTitle(string DepartmentAbbreviation) {
          List&lt;TaxonomyItem&gt; Divisions = TaxonomyFromCMS.GetAllItems(DomainDataConstants.DivisionAndDepartment.TAXONOMY_ID);
          List&lt;TaxonomyItem&gt; Departments = new List&lt;TaxonomyItem&gt;();
  
          Divisions.ForEach(delegate(TaxonomyItem Division) {
              Departments.AddRange(Division.SubTaxonomyItems);
          });
  
          TaxonomyItem Result = (from d in Departments
                                 where d.Name == DepartmentAbbreviation
                                 select d).FirstOrDefault();
  
          return Result == null ? "" : Result.Title;
      }
  </code></pre>
  
  <p>It first reads all of the Divisons (which there are only 3) but those divisions have many Departments below them as SubTaxonomyItems.  Currently I step through each of the Divisions and extract out each of the Departments and put them in a List called Departments.  Then I use Linq to search for the specific item.</p>
  
  <p>It works great but I would love to skip/consume that first step of getting the sub items.  I have tried the following line that doesn't seem to work:</p>
  
  <pre><code>TaxonomyItem Result = (from d in Departments.SubTaxonomyItems
  </code></pre>
  
  <p>I then through perhaps some sort of lambda with a foreach of the Departments.SubTaxonomyItems that contains a yeild statement.  That may be the trick, but I couldn't get it to work.  Looking into the yeild statement it seems there can be a way if I make some extension method.  But I am wanting to see if it can be done inline and like the following pseudo code:</p>
  
  <pre><code>    public string GetDepartmentTitle(string DepartmentAbbreviation) {
          List&lt;TaxonomyItem&gt; Divisions = TaxonomyFromCMS.GetAllItems(DomainDataConstants.DivisionAndDepartment.TAXONOMY_ID);
  
          TaxonomyItem Result = (from d in Divisions.ForEach(delegate(TaxonomyItem Division) {
                                   yeild return Divison.SubTaxonomyItems;
                                 }) AS Dps
                                 where Dps.Name == DepartmentAbbreviation
                                 select Dps).FirstOrDefault();
  
          return Result == null ? "" : Result.Title;
      }
  </code></pre>
  
  <p>Is this possible this way or some other way I am not seeing?  Can it even be done without an extension method?</p>