When is it better to use a List vs a LinkedList?
In most cases, List
is more useful. LinkedList
will have less cost when adding/removing items in the middle of the list, whereas List
can only cheaply add/remove at the end of the list.
LinkedList
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 a List
is essentially just an array (with a wrapper) random access is fine.
List
also offers a lot of support methods - Find
, ToArray
, etc; however, these are also available for LinkedList
with .NET 3.5/C# 3.0 via extension methods - so that is less of a factor.