dotnet / roslynator

Roslynator is a set of code analysis tools for C#, powered by Roslyn.

Home Page:https://josefpihrt.github.io/docs/roslynator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add performance refactoring for IList Last, First or ElementAt

Nixxen opened this issue · comments

Product and Version Used:
Visual Studio Professional 2022, 17.8.3
.Net 6.0
Rosslynator extension, 4.11.0

Index access versus list methods context: https://rules.sonarsource.com/csharp/RSPEC-6608/

Steps to Reproduce:

  1. Populate a list, someList.
  2. Access the first element through someList.First().
  3. Access the third element through someList.ElementAt(2).
  4. Access the first element through someList.Last().

Actual Behavior:
No suggestions.

Expected Behavior:
Suggestions:

someList[0];
someList[2];
someList[^1];

First and ElementAt is already implemented as a part of RCS1246.

But Last is not implemented yet, so that's good idea.