C# | Array vs ArrayList

Arrays: An array is a group of like-typed variables that are referred to by a common name. 

Example:

// C# program to demonstrate the Arrays
using System;
 
class TECH {
 
    // Main Method
    public static void Main(string[] args)
    {
 
        // creating array
        int[] arr = new int[4];
 
        // initializing array
        arr[0] = 47;
        arr[1] = 77;
        arr[2] = 87;
        arr[3] = 97;
 
        // traversing array
        for (int i = 0; i < arr.Length; i++) {
 
            Console.WriteLine(arr[i]);
        }
    }
}

Output:

47
77
87
97

ArrayList: ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dynamic memory allocation, adding, searching and sorting items in the list. 

Example:

// C# program to illustrate the ArrayList
using System;
using System.Collections;
 
class TECH {
 
    // Main Method
    public static void Main(string[] args)
    {
 
        // Create a list of strings
        ArrayList al = new ArrayList();
        al.Add("Atchu");
        al.Add("Atshaya");
        al.Add(10);
        al.Add(10.10);
 
        // Iterate list element using foreach loop
        foreach(var names in al)
        {
            Console.WriteLine(names);
        }
    }
}

Output:

Atchu
Atshaya
10
10.1

Difference Between Array and ArrayList

FeatureArrayArrayList
MemoryThis has fixed size and can’t increase or decrease dynamically.Size can be increase or decrease dynamically.
NamespaceArrays belong to System.Array namespaceArrayList belongs to System.Collection namespace.
Data TypeIn Arrays, we can store only one datatype either int, string, char etc.In ArrayList we can store different datatype variables.
Operation SpeedInsertion and deletion operation is fast.Insertion and deletion operation in ArrayList is slower than an Array.
TypedArrays are strongly typed which means it can store only specific type of items or elements.ArrayList are not strongly typed.
nullArray cannot accept null.ArrayList can accepts null.

Chockalingam