A sequence is sorted with OrderBy and then reversed, which OrderByDescending does in one pass

tx0/csharp:sort-then-reversestrictwarningperformance/algorithmicdepth fastperformance

What it finds

OrderBy(k).Reverse() sorts and then buffers the whole result again to reverse it. OrderByDescending(k) sorts in the wanted order directly.

From the rule's source, sort_then_reverse.rs.

Example from the rule's tests
using System.Collections.Generic;using System.Linq; class Scores{    IEnumerable<int> Best(IEnumerable<int> scores) => scores.OrderBy(s => s).Reverse();tx0 reports: the sorted sequence is reversed afterwards}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/csharp:sort-then-reverse" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/csharp:sort-then-reverse] reason="..."

tx0 explain tx0/csharp:sort-then-reverse shows the same in the terminal. Found a false positive? Report it.