Overview
The System.Collections namespace contains non‑generic collection classes that
implement IEnumerable and ICollection interfaces. These types provide
various data structures such as dynamic arrays, hash tables, stacks, and queues.
Key Types
| Class / Interface | Description |
|---|---|
| ArrayList | A dynamically sized array of Object references. |
| Hashtable | A collection of key/value pairs that are organized based on the hash code of the key. |
| List<T> | A generic dynamic array. |
| Dictionary<TKey,TValue> | A generic collection of key/value pairs. |
| Stack<T> | Represents a simple last‑in‑first‑out (LIFO) non‑generic collection of objects. |
| Queue<T> | Represents a first‑in‑first‑out (FIFO) collection of objects. |
Example: Using ArrayList
// Create an ArrayList and add items
ArrayList list = new ArrayList();
list.Add(1);
list.Add("two");
list.Add(DateTime.Now);
// Iterate over items
foreach (object item in list)
{
Console.WriteLine($"{item} (Type: {item.GetType()})");
}