As mentioned in this other post, there are two ways to alter the direction of the ordering of a C# List (or any Enumerable):
- use the
OrderByDescending()method. - add
.Reverse()at the end.
In my code, I have a lot of lines like these ones:
if (bDirection)
list.OrderBy(...);
else
list.OrderByDescending(...);
I would like to replace this by the following oneliner:
list.OrderBy(..., bDirection);
, where the boolean bDirection decides in which direction the ordering should be done.
Does this exist?
Thanks in advance