← All recipes
Moderne licensed

Find Count() comparison that could be optimized

Recipe IDOpenRewrite.Recipes.CSharp.CodeQuality.Linq.FindOptimizeCountUsageArtifactOpenRewrite.Recipes.CSharp.CodeQuality

Detect Count(pred) == n and Count() > n comparisons which could use Where().Take(n+1).Count() or Skip(n).Any() for better performance.

Single recipecsharplinqperformancecode-qualityProprietary

Usage

This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe OpenRewrite.Recipes.CSharp.CodeQuality.Linq.FindOptimizeCountUsage

If the recipe isn’t available locally, install it with:

mod config recipes nuget install OpenRewrite.Recipes.CSharp.CodeQuality