title: Build tree type list by recursively checking parent-child relationship C#
body: <p>I have One class that has a list of itself so it can be represented in a tree structure.</p>
  
  <p>I am pulling a flat list of these classes and want to unflatten it.</p>
  
  <pre><code>public class Group
  {
       public int ID {get;set;}
  
       public int? ParentID {get;set;}
  
       public List&lt;Group&gt; Children {get;set;}
  
  }
  </code></pre>
  
  <p>I want to be able to do the following</p>
  
  <pre><code>List&lt;Group&gt; flatList = GetFlatList() //I CAN ALREADY DO THIS
  List&lt;Group&gt; tree = BuildTree(flatList);
  </code></pre>
  
  <p>The ParentID related to the ID property on its parent group if that wasnt obvious.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>There is some confusion as to why I am returning a list and not a single object.</p>
  
  <p>I am building a UI element that has a list of items, each of why has a child. So the initial list DOES NOT have a root node. It seems all of the solutions so far do not work.</p>
  
  <p>What this means is I essentially need a list of tree type structures using Group class.</p>