Pre-Existing Collections

For the greatest amount of flexibility, the System.Collections namespace contains several collection classes that can be instantiated and used immediately. These pre-existing classes are designed for a wide variety of computing tasks requiring data structures.

The ArrayList Collection

Normal arrays have a fixed size, and once they fill up, you're either stuck or have to craft a work around. The ArrayList collection addresses this very problem through its ability to dynamically resize itself on-the-fly. Listing 26.1 shows how to use the ArrayList collection.

Listing 26.1. ArrayList Collection Example
 using System; using System.Collections; /// <summary> /// ArrayList example. /// </summary> class ArrayListExample { static ...

Get C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.