C#

C#

Made by DeepSource

Using inefficient methods First()/Last() on LinkedList<T> CS-P1024

Performance
Major

The methods First() and Last() come from the Enumerable interface defined in System.Linq. While they may be appropriate for other structures and scenarios, they are not performant for LinkedList<T>. Consider using LinkedList<T>'s own properties First and Last as they're efficient and tailored for this very purpose.

Bad Practice

var first = list.First();

Recommended

var first = list.First;

References