using System.Collections.Generic;
public class Comp{ public string Id{get;set;} public string ParentId{get;set;} }
public static List<Comp> data=new List<Comp>(){
new Comp(){Id = "1", ParentId = ""},
new Comp(){Id = "2", ParentId = "1"},
new Comp(){Id = "3", ParentId = "1"},
new Comp(){Id = "4", ParentId = "2"},
new Comp(){Id = "5", ParentId = "2"},
new Comp(){Id = "6", ParentId = "3"},
new Comp(){Id = "7", ParentId = "10"},
new Comp(){Id = "8", ParentId = "11"},
new Comp(){Id = "9", ParentId = ""},
new Comp(){Id ="10", ParentId = ""},
new Comp(){Id = "11", ParentId = ""}
public static List<string> GetChildsFor(string Id)
List<string> result=new List<string>();
var childs=data.Where(o=>o.ParentId==Id).Select(o=>o.Id);
foreach(var childId in childs)
result.AddRange(GetChildsFor(childId));
public static void Main()
foreach(var testId in new string[]{"1","2","6"})
var result=GetChildsFor(testId);
Console.WriteLine(testId + ": " + string.Join(", ", result.OrderBy(o=>o)));