1

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.

1
  • 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. Commented Feb 7, 2014 at 9:16

1 Answer 1

5

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.

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

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.