I have a method which sorts a List of Clients.
There are two parameters I want to sort by. I am well aware of the
List.OrderBy(x => x. [...]).ThenBy...
Method but my situation is a bit different:
switch(mySortType)
{
case SortType.mostVisits:
clients = clients.OrderBy(x => x. and so on...)
break;
More cases with different sortTypes
}
And after that I would like to sort after a Boolean parameter, but only if the settings tell the method to do so via another bool. Ist there a way to say something like
clients = clients.OrderBy(Current).ThenBy(x => x.param).ToList()?
I could of course have an if() in every case
case SortType.MostVisits:
if(settingsTellsMeToDoSo)
clients = clients.OrderBy(x=>x.numberOfVisits).ThenBy(x => x.param).ToList();
else clients = clients.OrderBy(x => x.numberOfVisits).ToList();
and then use the simple ThenBy Method but I thaught that there has to be an easier way to do it.
I hope you got my question right. I am not sure whether or not I was able to explain well enough...
regards, Eric