I have an array that stores the order that I want to sort a list by.
SortOrderArray: "Color", "Volume", "Weight"
So I want to order my list by Color, Volume, then Weight
MyList.OrderBy(a=>a.Color).ThenBy(a=>a.Volume).ThenBy(a=>a.Weight).ToList();
So that's pretty good. Now, I want to be able to write a function that does this sorting based on the sortOrder array I send in:
public List<row> GetSortedList(List<row> list, string[] sortOrder){
???
}
I can't figure out how to do this without writing a linq query for every combination of sortOrders (27 different queries just seems like the worst way to accomplish this, and has a fairly high possibility of me making a tiny mistake). I would like to be able to just write 3 linq queries that reorders the list according to each of the 3 sorting methods, something like this:
switch(sortOrder[0]){
Sort by the first sort method
}
switch(sortOrder[1]){
Sort by the second sort method
}
switch(sortOrder[2]){
Sort by the third sort method
}
But if I try doing the above code, it just resorts it each time, instead of doing sub-sorts after the one above it. Hope that is clear, any help would be appreciated.