Both ArrayList and Arrays are used to store list of values in C#., but there are some difference between both. In this article we discuss about what are the differences between Array and ArrayList.
string[] sNames = new string[10];
Arrays are accessible by index and in general index starts with 0(zero).
Whereas ArrayList is generated from System.Collection namespace. ArrayLists are not fixed length type and we can declare ArrayList as shown below.
ArrayList empInfo = new ArrayList();
empInfo.Add("John");
empInfo.Add(1);
empInfo.Add(10000.23);
string[] sNames = new string[10];
Console.WriteLine(sNames[0]);
(OR)
foreach(string name in sNames)
Console.WriteLine(name);
We can access ArrayList as shown below.
ArrayList empInfo = new ArrayList();
empInfo.Add("John");
empInfo.Add(1);
empInfo.Add(10000.23);
foreach (string name in empInfo)
Console.WriteLine(name.ToString());