I have a C# custom object list that I need to sort by two different variables one is a boolean and the other is a string. I can sort by either of the criteria, but
I have a class that creates CSV files using List
in a >
_Records
variable. I needed way to sort it after the fact, and LINQ was no good.
This is what I created as a multi-sort by passing in the indexes of the columns I wanted to sort.
public void OrderBy(params int[] columnIndexes)
{
_Records.Sort((x, y) =>
{
foreach (int i in columnIndexes)
{
int result = string.Compare(x[i], y[i]);
if (result != 0)
return result;
}
return 0;
});
}
Usage would then be...
csv.OrderBy(1, 3, 5);