Implementation of C# ArrayList class
Program.cs
using System.Collections;

ArrayList al = new ArrayList();
al.Add("Apple");
al.Add("Banana");
al.Add(50);
al.Add("Cherry");
al.Add("Durian");
al.Add("Apple");
Console.WriteLine("ArrayList: ");
foreach(var fruits in al)
{
    Console.Write(fruits+" ");
}

Console.WriteLine("\n\nThird element: "+al[3]);
Console.WriteLine("Size of ArrayList: "+al.Count);

al.RemoveAt(2); //removed 50
al.Sort();
Console.WriteLine("\nSorted elements: ");
foreach(var fruits in al)
{
    Console.Write(fruits+" ");
}
Console.WriteLine();
Output
kodingwindow@kw:~/csharp$ dotnet run
ArrayList: 
Apple Banana 50 Cherry Durian Apple 

Third element: Cherry
Size of ArrayList: 6

Sorted elements: 
Apple Apple Banana Cherry Durian 
kodingwindow@kw:~/csharp$ 
Advertisement