The following table lists the differences between Array and ArrayList in C#.
|Must include System namespace to use array.||Must include System.Collections namespace to use ArraList.|
Array Declaration & Initialization:
ArrayList Declaration & Initialization:
|Array stores a fixed number of elements. The size of an Array must be specified at the time of initialization.||ArrayList grows automatically and you don't need to specify the size.|
|Array is strongly typed. This means that an array can store only specific type of items\elements.||ArrayList can store any type of items\elements.|
|No need to cast elements of an array while retrieving because it is strongly typed and stores a specific type of items only.||The items of ArrayList need to be cast to an appropriate data type while retrieving. So, boxing and unboxing happens.|
|Performs faster than ArrayList because it is strongly typed.||Performs slows because of boxging and unboxing.|
|Use static helper class Array to perform different tasks on the array.||ArrayList itself includes various utility methods for various tasks.|
Visit Array or ArrayList in the C# tutorials section for more information.
- Searching in C# array
- How to count elements in C# array?
- How to combine two arrays without duplicate values in C#?
- How to get a comma separated string from an array in C#?
- How to remove duplicate values from an array in C#?
- How to sort an array in C#?
- How to sort object array by specific property in C#?
- How to sort the generic SortedList in the descending order?
- Difference between Hashtable and Dictionary