As I understand Linked Lists are useful if I need a list where I need to remove, or add items multiple times after the declaration - things that are not possible/harder to do with an array. But basically I can do the same thing with List Class in C#. So my question is, what is the difference between the two?
Asked
Active
Viewed 279 times
0
-
A [List](https://referencesource.microsoft.com/#mscorlib/system/collections/generic/list.cs,cf7f4095e4de7646) wraps an array. A [LinkedList](https://referencesource.microsoft.com/#System/compmod/system/collections/generic/linkedlist.cs,df5a6c7b6b60da4f) connects cells between them: [Creating a very simple linked list](https://stackoverflow.com/questions/3823848/creating-a-very-simple-linked-list). Linked lists (single/double/trees) are speed optimized but requires more memory. [Implementing Linked List (C# Corner)](https://www.c-sharpcorner.com/article/linked-list-implementation-in-c-sharp/). – Jan 19 '21 at 10:18
-
A list allows access to any of its elements with O(1) complexity, but a linked list has O(N) complexity (to get to the last element you need to visit all the preceeding elements). So a list is indexable, but a linked list is not easily indexable. That's a pretty major difference. – Matthew Watson Jan 19 '21 at 10:20
-
1Here's an answer to your question https://stackoverflow.com/questions/169973/when-should-i-use-a-list-vs-a-linkedlist – Volodymyr Osadchuk Jan 19 '21 at 10:24
-
Take a look at [Difference between Linked List and Arrays](https://www.faceprep.in/data-structures/linked-list-vs-array/) and [Linked List vs Array](https://www.geeksforgeeks.org/linked-list-vs-array/) and [Difference between Array and Linked List](https://www.studytonight.com/data-structures/linked-list-vs-array) and [Difference Between Array and Linked List](https://techdifferences.com/difference-between-array-and-linked-list.html) – Jan 19 '21 at 10:26
-
Comments != Answers – Rand Random Jan 19 '21 at 10:27
-
Duplicate of [Difference between List
and LinkedList – Jan 19 '21 at 10:28](https://stackoverflow.com/questions/4279020/difference-between-listt-and-linkedlistt) and [LinkedList vs List ](https://stackoverflow.com/questions/5870887/linkedlist-vs-listt) and [When should I use a List vs a LinkedList](https://stackoverflow.com/questions/169973/when-should-i-use-a-list-vs-a-linkedlist/29263914) -
Yes, I found those threads, but I was not sure if there is a difference between the LinkedList class, and a single linked list which is written by me. – samivagyok Jan 19 '21 at 10:31
-
Also found this article: [Linked Lists vs. Arrays/Lists](https://towardsdatascience.com/linked-lists-vs-arrays-78746f983267) – Jan 19 '21 at 10:41
-
1Thank you everyone, my question has been answered! – samivagyok Jan 19 '21 at 10:46
-
`Yes, I found those threads, but I was not sure if there is a difference between the LinkedList class, and a single linked list which is written by me.` That is not what your question says. – mjwills Jan 19 '21 at 11:00
1 Answers
-2
I Linked list you have one or two direction to explore the list
C# List class is a wrapper which gives a combined options of List and Array it gives many more option which makes writing really easier like: foreach, querying the list, approach Nth element and many more while the object is quite efficient

L Y
- 1
- 1
-
2Thank you for taking the time to share your knowledge & experience. But your answer has a low quality. Sometimes a comment or a flag/close may be more relevant. To help you improve your answersplease read [How do I write a good answer](https://stackoverflow.com/help/how-to-answer), [How do I write a good answer to a question](https://meta.stackexchange.com/questions/7656/how-do-i-write-a-good-answer-to-a-question) & [Answering technical questions helpfully](https://codeblog.jonskeet.uk/2009/02/17/answering-technical-questions-helpfully). – Jan 19 '21 at 10:34
-
1A linked list can implement `IEnumerable
` to be used with `foreach` and `Linq`. Lists/arrays and linked lists have both advantages and disadvantages, mainly in terms of speed vs memory. – Jan 19 '21 at 10:34