The ArrayList class is designed to hold heterogeneous collections of objects. However, it doesn't always offer the best performance. I think you should use List<T> instead of using ArrayList
To play demo you need to create a new console project, then add code as below
using System;
using System.Collections;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
//Init ArrayList
ArrayList list = new ArrayList();
list.Add("One");
list.Add(2);
list.Add("Three");
list.Add(4);
//Get item in ArrayList using for loop
for (int i = 0; i < list.Count; i++)
Console.WriteLine("{0}", list[i]);
//Get item in ArrayList using foreach loop
foreach (var i in list)
Console.WriteLine($"{i}");
Console.ReadLine();
}
}
}
You can see the ArrayList is one of the most flexible data structure from C# collections. You can Sort, Join, Remove, Find...items from ArrayList
// Remove element in ArrayList at position 1
list.RemoveAt(1);
// Insert word at the beginning of ArrayList.
list.Insert(0, "C#");
// Remove first two words from ArrayList.
list.RemoveRange(0, 2);
// Sort the ArrayList.
list.Sort();
// Clear all items in ArrayList.
list.Clear();
// Count items in ArrayList
Console.WriteLine(list.Count);
//Init ArrayList
ArrayList list2 = new ArrayList();
list2.Add("c-sharpcode.com");
list.AddRange(list2);