Aller au contenu

Combine linq methods (ARCH605)

Ce contenu n’est pas encore disponible dans votre langue.

Key dotnet.performance.combine-linq-methods · Severity info · Category performance · Principle Kiss

Instead of separate calls like Where then First, putting the predicate into First(...) scans the collection in a single pass.

var first = items
.Where(i => i.IsActive)
.First();
var first = items
.First(i => i.IsActive);

Combine filter and selection predicates into one LINQ call.