I must use a self-coded comparer to sort a list of objects.
myObjectList.Sort(new MyComparer(_sortExpression, _sortDirection));
How can I append a 2nd expression and direction to sort by if values on 1st expression are equal?
I mean e.g.: Sort by last name and then if equal by first name. But I must use my own comparer.
myObjectList.Sort(
new MyComparer(new string[]{_exp1, _exp2}, new string[]{_dir1, _dir2}));
Thanks in advance!
Lord Vader
You could define an extension method that allows to chain comparers as follows:
Usage:
This sorts the list by the first comparer and, if two items are equal, then by the second comparer.
Alternative solution:
Usage: