I am wondering what the exact difference is between a Array, ArrayList and a List (as they all have similar concepts) and where you would use one over the other.
Example:
Array
For the Array we can only add types that we declare for this example an int.
int[] Array = new Int[5]; //Instansiation of an array
for(int i = 0; i < Array.Length; i++)
{
Array[i] = i + 5; //Add values to each array index
}
ArrayList
We can add values just like a Array
ArrayList arrayList = new ArrayList();
arrayList.Add(6);
arrayList.Add(8);
List
Again we can add values like we do in an Array
List<int> list = new List<int>();
list.Add(6);
List.Add(8);
I know that in a List you can have the generic type so you can pass in any type that you cannot do in an Array but my exact questions are:
- Where would you use one over the other?
- The exact difference functionality wise between the three?