1

Is there any point of using those data types other then legacy code? Other data types like Dictionary or Graph are understandably used because they provide extra / different functionality. But array, LinkedList or ArrayList have less of a functionality and sometimes worst performance then List (ArrayList is less memory efficient in value types)

Then why use them at all?

Note: this is not an opinion - based question. All I want to know is use cases for these types

Another Note: I know about Linked list's O(1) insert time. I am asking when should it be utilized over the standard List, which has O(1) access time? When it is better to use? (and the question about ArrayList and array remains)

1
  • all containers have pro and cons.... from Complexity O(n) to sorting functionalities Commented Sep 8, 2020 at 9:29

2 Answers 2

2

ArrayList? sure: don't use it, basically ever (unless you don't want to migrate some legacy code, or can't because somebody has unwisely used BinaryFormatter).

LinkedList<T>, however, is not in the same category - it is niche, but it has uses due to cheap insertion/removal/etc, unlike List<T> which would need to move data around to perform insertion/removal. In most scenarios, you probably don't need that feature, so: don't use it unless you do?

Sign up to request clarification or add additional context in comments.

3 Comments

But which List<T> you mean? You can't instantiate List<T>, so there is no List<T>.
@Omid.N um... yes you can (instantiate List<T>); it isn't abstract (are you thinking of Java? note the question has a C# tag, so I'm talking .NET here)
Ah! sorry I thought it is a java question.
0

LinkedList

Here is a list of differentiators from the List implementation. You use it when the items in the list need to maintain a specific order (hence the next and previous references).

Represents a doubly linked list.

LinkedList<T> provides separate nodes of type LinkedListNode<T>, so insert and removal are O(1) operations.

You can remove nodes and reinsert them, either in the same list or in another list, which results in no additional objects allocated on the heap. Because the list also maintains an internal count, getting the Count property is an O(1) operation.

Each node in a LinkedList<T> object is of the type LinkedListNode<T>. Because the LinkedList<T> is doubly linked, each node points forward to the Next node and backward to the Previous node.

List Vs ArrayList

ArrayList is a deprecated implementation used in the past. Prefer List<T> generic implementation in any new code.

As a generic collection, List<T> implements the generic IEnumerable<T> interface and can be used easily in LINQ

ArrayList belongs to the days that C# didn't have generics. It's deprecated in favor of List<T>. You shouldn't use ArrayList in new code that targets .NET >= 2.0 unless you have to interface with an old API that uses it.

Array vs List

Array is a fixed size collection and it supports multiple dimensions. It is the most efficient of the three for simple insert and iterations.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.