Select a result to preview
LinkedList<T> is a doubly linked list where each node points to previous and next nodes. It is useful when you already keep node references and need frequent O(1) inserts/removes around those nodes.
Unlike array-backed collections, linked lists do not store elements contiguously:
List<T>.graph LR
H[head] --> N1[node a]
N1 <--> N2[node b]
N2 <--> N3[node c]
N3 --> T[tail]var list = new LinkedList<string>();
var a = list.AddLast("A");
list.AddLast("C");
list.AddAfter(a, "B");
list.Remove("C");
LinkedList<T> for index-based access causes O(n) scans and can underperform List<T> significantly. Prefer List<T>/arrays for index-heavy workloads, or store node handles when linked-list locality edits are truly required.LinkedListNode<T> instances as anchors (AddBefore, AddAfter, Remove) throws because a node must belong to the target list context. Check node.List before using node handles and re-find/re-add nodes when needed.List<T> for traversal-heavy workloads unless node-local O(1) edits are the dominant operation.LinkedList<T> vs List<T>: linked list wins for O(1) local edits around known nodes; list usually wins for traversal and random access.LinkedList<T> vs Queue<T>/Stack<T>: queue/stack APIs are simpler and often faster when you only need FIFO/LIFO behavior.LinkedList<T> often slower than List<T> in real workloads despite O(1) inserts/removes?
CPU cache locality dominates many workloads. List<T> keeps data contiguous, while linked-list nodes are scattered and require pointer chasing.
LinkedList<T> the right choice in .NET?
When your algorithm already stores LinkedListNode<T> handles and performs many localized inserts/removes around them.
LinkedList<T> to List<T>?
If code frequently searches by index/value before each operation, you are paying O(n) traversal repeatedly and should usually switch to List<T> or another structure.