Zum Inhalt springen

Use indexer instead of linq (ARCH607)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key dotnet.performance.use-indexer-instead-of-linq · Severity info · Category performance

Accessing the first or last element of a list via First()/Last() adds iterator overhead; the indexer is O(1).

var firstItem = list.First();
var lastItem = list.Last();
var firstItem = list[0];
var lastItem = list[^1];

Use [0] or [^1] on indexable collections.