G
Guest
I need some help with a multilevel sorting problem with the List<>.
I have a List<ItemToSort> ( see below ) that needs to be sorted in the
following manner:
Sort by Level1Id ( ok that was the easy part)
Within the unique Level1Id's, sort by Level2Id
Within the unique level2Id's sort by name, then description.
I looked at doing this with some foreach and list.FindAll() and copying the
list into a new list, but this had some code smells. I know there must be a
better solution than making many copies of a list.
The true code is much more complex, and uses custom Comparers, but this
would illustrate the problem. Actually, if I get to the third level (
remember the first one was ez), I can take it from there.
public class ItemToSort
{
public int Level1Id;
public string Level2Id;
public string Name;
public string Description;
}
Not necessarily looking for the code, but some guidlines.
Thanks!
I have a List<ItemToSort> ( see below ) that needs to be sorted in the
following manner:
Sort by Level1Id ( ok that was the easy part)
Within the unique Level1Id's, sort by Level2Id
Within the unique level2Id's sort by name, then description.
I looked at doing this with some foreach and list.FindAll() and copying the
list into a new list, but this had some code smells. I know there must be a
better solution than making many copies of a list.
The true code is much more complex, and uses custom Comparers, but this
would illustrate the problem. Actually, if I get to the third level (
remember the first one was ez), I can take it from there.
public class ItemToSort
{
public int Level1Id;
public string Level2Id;
public string Name;
public string Description;
}
Not necessarily looking for the code, but some guidlines.
Thanks!