When is it better to use a List vs a LinkedList?
C# – When should I use a List vs a LinkedList
cdata structureslinked listnetvb.net
Related Topic
- C# – Deep cloning objects
- C# – Should ‘using’ directives be inside or outside the namespace
- Python – the difference between Python’s list methods append and extend
- Java – When to use LinkedList over ArrayList in Java
- C# – When should I use a struct rather than a class in C#
- C# – a NullReferenceException, and how to fix it
- Python – How to remove a key from a Python dictionary
- Scala: list.flatten: no implicit argument matching parameter type (Any) = > Iterable[Any] was found
Best Answer
In most cases,
List<T>
is more useful.LinkedList<T>
will have less cost when adding/removing items in the middle of the list, whereasList<T>
can only cheaply add/remove at the end of the list.LinkedList<T>
is only at it's most efficient if you are accessing sequential data (either forwards or backwards) - random access is relatively expensive since it must walk the chain each time (hence why it doesn't have an indexer). However, because aList<T>
is essentially just an array (with a wrapper) random access is fine.List<T>
also offers a lot of support methods -Find
,ToArray
, etc; however, these are also available forLinkedList<T>
with .NET 3.5/C# 3.0 via extension methods - so that is less of a factor.