Difference Between Array and Arraylist in C#
Array vs ArrayList in C#:
Here is the picture:
Array | ArrayList |
Array allows to store a series of value. | ArrayList allows to store a collection of value. |
Values in array must be of same data type. | Values can be of different data types. |
Array is a datatype. | ArrayList is a datatype collection. |
Array size, once declared, can not be changed at run time. | ArrayList allows dynamic resizing. |
Array is strongly typed. | ArrayList is not strogly type. That why it can store any data type. |
Arrays are layed out contiguoumemory. | Internal structure of ArrayList is array. |
Values can be retrieve to the declareddatatype of the array. ex: int[] intArr=new int[5]; int i=intArr[1]; | Values must be converted to a string, because there is no way to be certain what it is. ex: string item=Convert.ToString(myLst[0]); |
Faster | Slower than array |
Better when efficiency is matter and number of elements is known. | Better when number of elements is not known. |