C#

C#

Made by DeepSource

Consider rewriting chained .OrderBy() calls as .ThenBy() CS-P1008

Performance
Major

The .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().

Bad Practice

var ordered = people.OrderBy(p => p.Name)
                    .OrderBy(p => p.Age);

Recommended

var ordered = people.OrderBy(p => p.Name)
                    .ThenBy(p => p.Age);

Reference