How do I get the n-th element in a LinkedList?

The ElementAt extension method will do it:

// This is 0-based of course
var value = linkedList.ElementAt(n);

Don’t forget this is an O(n) operation because LinkedList<T> doesn’t provide any more efficient way of accessing an item by index. If you need to do this regularly, it suggests that you shouldn’t be using a linked list to start with.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)