Skip to content

Add performance refactoring for IList Last, First or ElementAt #1426

@Nixxen

Description

@Nixxen

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];

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions