ArrayList Class
Part of my 2008 study notes for exam 70-536 (.NET Framework 2.0).
Overview
- Resizeable, unordered, index-based collection.
- Suffers from boxing/unboxing when working with value types.
- Implements IEnumerator, allowing foreach operations.
- The IEnumerator is a .NET implementation of the Iterator Pattern.
Good practice
- When possible, use a generic collection instead of the object-based ArrayList.
Examples
Adding and Removing Elements
ArrayList a = new ArrayList();
a.Add(16);
a.AddRange(new object[] { "Hello", "World" });
a.Insert(0, "Start");
a.InsertRange(2, new int[] { 32, 64 });
foreach (var o in a) { Console.WriteLine(o); }
a.Remove("Hello");
a.RemoveAt(1);
a.RemoveRange(1, 2);
foreach (var o in a) { Console.WriteLine(o); }
Checking Existence
ArrayList a = new ArrayList();
a.AddRange(new object[] { "Hello", "World" });
Console.WriteLine(a.Contains("World") ? "World Found" : "World Missing");
You May Also Like
BinaryReader Class and BinaryWriter Class
Used to read and write binary data from streams. Call the correct Read methods when using a BinaryReader.
BitArray Class
Contains an array of true/false values. Resizable through the Length property. Supports bitwise operations.
BitVector32 structure and BitVector32.Section structure
Used to manipulate the bits of a 32 integer. Used to pack multiple small numbers into one when storage is an issue.



