i have this code that take a collection and groups by a string field:
var groupByIssueType = issues.GroupBy(r => r.IssueType);
i now want to loop through each group but i want to do that in a specify order. something like . .
foreach (var issueType in groupByIssueType)
{
}
The problem is that the order is not alphabetic so i can’t just do an
OrderBy(r=>r.Name)
or something like that. . . i need a way to sort a grouped collection by its keys but using a custom sorting algorithm
So for example, lets say i have as my IssueTypes
“City Level”
“State Level”
“Country Level”
i want to loop through the “groupbyIssueType collection in the order Country, State, City
what would be the best way of doing that ?
You need to write an
IComparer<String>that uses your custom sort order.For example: