I’ve a list which contains a string and another list in it – sample code as follows:
List<Config> ConfigLists;
Here Config is a class containing 2 members:
- String Name
- List BinaryLists
where Binary is another class.
I want to sort ‘ConfigLists’ list based on ‘Name’ contained in each list item.
Can anyone please guide?
Also I would like to use a substring of ‘Name’ for sorting as the ‘Name’ would contain values like “Week 07”, “Week 09” etc where the substring I will take for comaparision is the numeric part of string (e.g. ’07’, ’09’ etc)
Linq should help here;
…which of course can be used to sort by a substring…
If you have a more complex sort order or want to avoid temporary strings in your sorting, you may want to instead use an IComparer to do the sorting for you;
The IComparer also works with “plain old” Sort if you don’t like Linq’s syntax.