You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Linq methods like First(), Last() and ElementAt() can be necessary on enumerable types that don't have an indexer. But for those that do, direct index access is a lot cheaper at runtime than their Linq counterpart and should be used instead.
When can it be ignored ?
This rule shouldn't be ignored.
Examples
publicstaticvoidTest(int[]arr){intfirst=arr.First();// Non-compliant, use arr[0]intlast=arr.Last();// Non-compliant, use arr[^1], or arr[arr.Length - 1] if C# < 8intthird=arr.ElementAt(2);// Non-compliant, use arr[2]}
Category : Performance
Severity : Warning
Why is this an issue ?
Linq methods like
First()
,Last()
andElementAt()
can be necessary on enumerable types that don't have an indexer. But for those that do, direct index access is a lot cheaper at runtime than their Linq counterpart and should be used instead.When can it be ignored ?
This rule shouldn't be ignored.
Examples
Asm code analysis
Using this C# code :
We get the following compiled asm code, showing the clear difference between the 2.
The text was updated successfully, but these errors were encountered: