In LINQ, is it possible to have conditional orderby sort order (ascending vs. descending).
Something like this (not valid code):
bool flag; (from w
You can even do more complex ordering and still keep it short:
var dict = new Dictionary() { [1] = "z", [3] = "b", [2] = "c" }; var condition = true; var result = (condition ? dict.OrderBy(x => x.Key) : dict.OrderByDescending(x => x.Value)) .Select(x => x.Value);