私はのリストを持っていますMyObject1:
public class MyObject1
{
   public int Id {get; set;}
   public int ParentId {get; set;}
}
List<MyObject1> list = new List<MyObject1>(); 
以下を使用してツリーを構築する必要がありますMyObject2。
public class MyObject2
    {
       public int Id {get; set;}
       public int ParentId {get; set;}
       // Here should be all child objects, that have .ParentId property is 
       // equal to .Id property of current node
       public List<MyObject2> Children = new List<MyObject2>();
    }
それを行う最速の方法は何ですか? たぶん、ビルドする前にソートlistする必要がありますIdか?ParentId
ETA 私の試み:
MyObject2 root = MyObject2(1, 0); // in constructor id, parentId 
foreach (MyObject1 obj1 in list)
{
  // Traversing all tree within root (let's say myTree), 
  //if myTree.ParentId = obj1.Id then:
  myTree.Children.Add(new MyObject2(obj1.Id, obj1.ParentId));
}
.Id問題は、ツリーにそのようなオブジェクトがまだない場合はどうなるでしょうか? これはそのための最良の方法ですか?