title: (ID/ParentID) list to Hierarchical list
body: <p><code>MyClass</code> consists of <code>ID</code> <code>ParentID</code> and <code>List&lt;MyClass&gt;</code> as <code>Children</code></p>
  
  <p>I have list of <code>MyClass</code> like this</p>
  
  <pre><code>ID  ParentID
  1   0
  2   7
  3   1
  4   5
  5   1
  6   2
  7   1
  8   6
  9   0
  10  9
  </code></pre>
  
  <p>Output (Hierarchical list) as <code>List&lt;MyClass&gt;</code></p>
  
  <pre><code>1 __ 3
   |__ 5__ 4
   |__ 7__ 2__ 6__ 8
       |__ 11
  
  9 __10
  </code></pre>
  
  <p>What is the simplest way to achieve this in linq?<br>
  P.S.: <code>ParentID</code> not sorted</p>
  
  <p><strong>Edit:<br>
  My try:</strong></p>
  
  <pre><code>class MyClass
  {
      public int ID;
      public int ParentID;
      public List&lt;MyClass&gt; Children = new List&lt;MyClass&gt;();
      public MyClass(int id, int parent_id)
      {
          ID = id;
          ParentID = parent_id;
      }
  }
  </code></pre>
  
  <p>initialize sample data and try to reach hierarchical data  </p>
  
  <pre><code> List&lt;MyClass&gt; items = new List&lt;MyClass&gt;()
  {
      new MyClass(1, 0), 
      new MyClass(2, 7), 
      new MyClass(3, 1), 
      new MyClass(4, 5), 
      new MyClass(5, 1), 
      new MyClass(6, 2), 
      new MyClass(7,1), 
      new MyClass(8, 6), 
      new MyClass(9, 0), 
      new MyClass(10, 9), 
      new MyClass(11, 7), 
  };
  
  Dictionary&lt;int, MyClass&gt; dic = items.ToDictionary(ee =&gt; ee.ID);
  
  foreach (var c in items)
      if (dic.ContainsKey(c.ParentID))
          dic[c.ParentID].Children.Add(c);
  </code></pre>
  
  <p>as you can see, lots of items I don't want still in the dictionary</p>