Sunday, February 18, 2007

Arrays vs ArrayLists in C#

Initially, I had a very hard time understanding the concept of Arrays vs. ArrayLists. So finally after browsing and searching on google and four textbooks for an explanation that makes sense, I put together these lists:

- Require a counter for accessing elements
- Need to use ReDim Preserve
- Type specific - data types must be same throughout the array
- Homogeneous data - same data type

- Do not require a counter
- No need to use ReDim Preserve
- Items can be removed
- Items can be sorted
- Items can be searched
- Items can be added at runtime
- Items can be replaced
- Can hold objects (custom or defined) and it is possible to have more than one data type objects in one arraylist
- Heterogeneous data - data type can differ from object to object
- Is a DataStructure in .NET
- Its capacity is increased if required as objects are added to it. So it frees programmer from the worries of array overflow.
- Can be made read only after adding elements to prevent unintentional modifications.
- Provides an overloaded method to perform binary search on Its objects.
- Implements IList interface using an array.

No comments: