title: Does PrincipalSearchResult<T> automatically dispose all elements in its collection?
body: <p>Can't find anything in the MSDN documentation on this.</p>
  
  <p>I.e. is it enough to do, say:</p>
  
  <pre><code>using(PrincipalSearcher searcher = ...)
  {
      foreach (var principal in searcher.FindAll())
      {
          ... do something ...
      } // The PrincipalSearchResult&lt;T&gt; returned by searcher.FindAll is disposed here
  }
  </code></pre>
  
  <p>which is what most examples I've seen do, or should I do:</p>
  
  <pre><code>using(PrincipalSearcher searcher = ...)
  {
      foreach(var principal in searcher.FindAll())
      {
          using (principal)
          {
              // ... do something ...
          }
      } 
  }
  </code></pre>
  
  <p>The latter (explicitly disposing each item during iteration) looks "safer" - i.e. conforms to the guideline to explicitly dispose all IDisposable objects - but it's a bit messy; for example, it precludes the use of LINQ to iterate over search results.</p>
  
  <p>In response to @Rup's comment:</p>
  
  <blockquote>
    <p>you could write a yield iterator that returned one result from the parent iterator </p>
  </blockquote>
  
  <p>Yes, I think that would work to enable LINQ.  Something like the following extension method:</p>
  
  <pre><code>public static IEnumerable&lt;T&gt; EnumerateAndDispose&lt;T&gt;(this IEnumerable&lt;T&gt; collection) where T : IDisposable
  {
      foreach (T item in collection)
      {
          using (item)
          {
              yield return item;
          }
      }
  }
  </code></pre>
  
  <p>which can be used as:</p>
  
  <pre><code>searcher.FindAll().EnumerateAndDispose().Select(... use LINQ ...)
  </code></pre>
  
  <p>But is it necessary? </p>