I'm pulling a dataset into a c# list and to sort it. It's a hierarchical menu:
sample object:
public class NavigationInfo
{
public Int32 Id { get; set; }
public Int32 ParentId { get; set; }
public String Text { get; set; }
public String Url { get; set; }
public Int32 Sort { get; set; }
}
The ParentId is recursive to Id and Sort is an ascending integer within the ParentId. How is that done using a collection of NavigationInfo
in List<NavigationInfo>
?
Best Solution
You can do something like:
UPDATE: You can also use LINQ and do an OrderBy on the List. This returns a new collection, but is a lot easier to order by multiple criteria, ascending or descending.