C#

C#

Made by DeepSource

Consider simplifying LINQ query by dropping explicit .Where() call CS-R1046

Anti-pattern
Major
Autofix

The expression .Where(predicate).Count() returns the number of elements satisfying the predicate. However, this entire expression can be simplified by dropping the .Where() call and directly passing the predicate to .Count(). This is more concise and succinct.

Bad Practice

var count = arr.Where(x => x % 5 == 0).Count();

Recommended

var count = arr.Count(x => x % 2 == 0);