I have a nested list,
List<List<String>> intable;
where I would like to sort all the columns. The problem is that the number of columns depends on user input.
Sorting the list like this works fine (assuming 4 columns for this example)
var tmp = intable.OrderBy(x => x[0]);
tmp = tmp.ThenBy(x => x[1]);
tmp = tmp.ThenBy(x => x[2]);
tmp = tmp.ThenBy(x => x[3]);
intable = tmp.ToList();
But, when I put it in a loop, like this:
var tmp = intable.OrderBy(x => x[0]);
for (int i = 1; i <= 3; i++)
{
tmp = tmp.ThenBy(x => x[i]);
}
intable = tmp.ToList();
it no longer works correctly, and sorts only the fourth column.