I have a c# list with no limits of levels with parentID´s. How do I organize the list, so the output would look like:
root1
----sub1
--------sub3
------------sub4
root2
----sub2
My list:
var categories = new List<categoryModel>();
categories.Add(new categoryModel { ID = 1, Name = "root 1", ParentID = 0 });
categories.Add(new categoryModel { ID = 2, Name = "root 2", ParentID = 0 });
categories.Add(new categoryModel { ID = 3, Name = "sub 1", ParentID = 1 });
categories.Add(new categoryModel { ID = 4, Name = "sub 2", ParentID = 2 });
categories.Add(new categoryModel { ID = 5, Name = "sub 4", ParentID = 6 });
categories.Add(new categoryModel { ID = 6, Name = "sub 3", ParentID = 3 });
public class categoryModel
{
public int ID { get; set; }
public string Name { get; set; }
public int ParentID { get; set; }
}