Search⌘ K

ArrayList

Explore how the ArrayList class in C# manages dynamic collections of objects. Learn to add, remove, and iterate items without predefined limits, while understanding casting challenges and why generic collections might be preferable for strong typing and type safety.

Introduction

When we need to store multiple items in one place, we can use arrays. We can use them to store a number items of the same type:

int[] points = new int[30]; // Array that can hold 30 integers

We can also iterate an array to process one item at a time:

for (int i  = 0; i < points.Length; i++)
{
	Console.WriteLine(points[i]);
}

Arrays are great, but they all suffer from one major shortcoming. That is,we have to know how many items our array will hold before we create and start ...