title: How to get an IEnumerable of child objects that can have child objects
body: <p>In C#, how is the best way to get an <code>IEnumerable&lt;T&gt;</code> of all child objects, where a child object can have a child?</p>
  
  <p>Here is an example:</p>
  
  <p>I have a class called <code>Test</code>, with the following ids:</p>
  
  <pre><code>int id
  
  int parentId
  </code></pre>
  
  <p>I have a <code>List&lt;Test&gt;</code> called <code>testItems</code> that is populated with many Test objects.</p>
  
  <p>Each <code>Test</code> object, has an <code>id</code>, and can have a <code>parentId</code> of another <code>Test</code> object in the <code>List</code>.</p>
  
  <p>If I have an <code>id</code>, how is the best way to get an <code>IEnumerable&lt;Test&gt;</code> that has all childs including childs of childs?</p>
  
  <p>Here is some more information:</p>
  
  <p>I have the following Test Objects:</p>
  
  <ul>
  <li>a</li>
  <li>b</li>
  <li>c</li>
  <li><p>d</p></li>
  <li><p>a has no parent</p></li>
  <li><p>b has a parent of a</p></li>
  <li><p>c has a parent of b</p></li>
  <li><p>d has a parent of c</p></li>
  </ul>
  
  <p>If I have the id of b, how can I get an <code>IEnumerable</code> that contains all children of c. This <code>IEnumerable</code> will contain c and d.</p>
  
  <p>Thanks.</p>