Simplify LINQ expression
Applies to: Visual Studio Visual Studio for Mac
This refactoring applies to:
What: Refactors instances of
Enumerable.Single() as well as the following Enumerable methods:
When: All instances where the method calls
SingleOrDefault(), and so on, doesn't have any arguments and is preceded by a
Where() expression. The input to the
Where() expression cannot be constructed as an expression tree.
Why: Removing the unnecessary call to the Enumerable for the
.Where() method improves readability and in some cases performance, see remarks.
Place your cursor within the
SomeEnumerableType.Where(<LambdaExpression>).Single()instance in visual studio.
Press Ctrl+. to trigger the Quick Actions and Refactorings menu.
Select Simplify LINQ expression
In some cases this refactoring may reduce performance. LINQ operations on
T are not optimized in this case and result in worse performance.
Submit and view feedback for