.OrderBy()
calls as .ThenBy()
CS-P1008The .OrderBy()
method allows you to specify the criteria according to which the elements must be ordered and returns a new ordering. Everytime the .OrderBy()
method is invoked, the previous ordering, if any, is lost, resulting in a wastage of resources. To preserve any previous ordering, rewrite subsequent .OrderBy()
methods as .ThenBy()
.
var ordered = people.OrderBy(p => p.Name)
.OrderBy(p => p.Age);
var ordered = people.OrderBy(p => p.Name)
.ThenBy(p => p.Age);