Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Everyone,

Array is a reference type,all the collection classes are also reference types..but why Collections are choosen by many over arrays ,As mentioned in the subject, is it only for it's dynamic behaviour...Please give me a scenario with example which expalins Collections behaviour..



Regards
Chaithanya M
Posted
Updated 25-Apr-11 1:02am
v2
Comments
Sergey Alexandrovich Kryukov 25-Apr-11 11:33am    
Your title contains the answer, a correct answer. Why bothering people with pointless question?
--SA

1 solution

Array is a fixed type: it's size must be known in advance of adding the elements. With the other collection types, you do not need to know the size in advance. You cannot extend the size of an array: you have to declare a bigger array and copy all the existing elements into it.

Additionally, it is difficult to re-order elements of an array, or to insert an element. With teh other collections, this is generally pretty simple.

Don't forget that most (if not all) collections have a ToArray method, which allows you the best of both worlds!
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Apr-11 11:34am    
A 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900