If I am not wrong Generic collection stores the objects of specific types.
For example, List<String>
stores objects of only String types.
Also String[] arr = new String[size]
stores the objects of String types.
Both also support IEnumerable
interface.
So I want to know the differences between Generic Collection and Arrays of Specific types.
Asked
Active
Viewed 5,615 times
1

Musakkhir Sayyed
- 7,012
- 13
- 42
- 65

Piyush
- 542
- 1
- 8
- 17
-
It is all about how do you want to use it. Array is obviously more compact (take less space), but also less flexible. You can convert any into any, but conversion takes time and memory. If you expect to have operations like `insert`, `add`, `delete`, `sort`, then use `List<>`. If your priority is to `find` by key, then both are bad (use `Hashtable` to example). Arrays are good to hold fixed size data (to example, to organize cyclic buffer) or for size (memory) optimizing. – Sinatr Feb 07 '14 at 09:16
1 Answers
4
An array
is fixed size. You define the size up front and that's it. A collection like List<T>
is of variable size. It supports adding and removing items from the collection. Behind the scenes a List<T>
uses an array
to store the items. It's smart enough to re-size the array
whenever necessary.
So you shouldn't think about generic vs array but collection vs array. There are also non-generic arrays but there are few scenarios where you would use those.
You can find the documentation for List<T>
here.

Wouter de Kort
- 39,090
- 12
- 84
- 103