C#

C#

Made by DeepSource

Passing an identity function to Select() is redundant CS-P1015

Performance
Major

The Select() method from System.Linq transforms an IEnumerable<T>'s elements based on the lambda specified. An identity function is a function that returns the same element unchanged that was passed as its argument. Since such a function does nothing useful, passing it to Select() does not modify the elements and is just a redundant expression. It is recommended that you drop such redundant expressions.

Bad Practice

var filtered = elements.Select(x => x).Where(x % 4 == 0);

Recommended

var filtered = elements.Where(x % 4 == 0);

Reference