CHAPTER 9 COLLECTIONS AND GENERICS
The System.Collections Namespace
When the .NET platform was first released, programmers frequently used the nongeneric collection
classes found within the System.Collections namespace, which contains a set of classes used to manage
and organize large amounts of in-memory data. Table 9-1 documents some of the more commonly used
collection classes of this namespace, and the core interfaces they implement.
Note Any .NET application built with .NET 2.0 or higher should ignore the classes in System.Collections in
favor of the corresponding classes in System.Collections.Generic. However, it is important to know the basics
of the nongeneric collection classes, as you might have some legacy software to maintain.
Table 9-1. Useful Types of System.Collections
System.Collections Class
Meaning in Life
Key Implemented Interfaces
ArrayList
Represents a dynamically sized
collection of objects listed in
sequential order.
IList, ICollection,
IEnumerable, and ICloneable
BitArray
Manages a compact array of bit
values, which are represented as
Booleans, where true indicates that
the bit is on (1) and false indicates
the bit is off (0).
ICollection, IEnumerable,
and ICloneable
Hashtable
Represents a collection of key/value
pairs that are organized based on
the hash code of the key.
IDictionary, ICollection,
IEnumerable, and ICloneable
Queue
Represents a standard first-in, firstout (FIFO) collection of objects.
ICollection, IEnumerable,
and ICloneable
SortedList
Represents a collection of key/value
pairs that are sorted by the keys and
are accessible by key and by index.
IDictionary, ICollection,
IEnumerable, and ICloneable
Stack
A last-in, first-out (LIFO) stack
providing push and pop (and peek)
functionality.
ICollection, IEnumerable,
and ICloneable
The interfaces implemented by these collection classes provide huge insights into their overall
functionality. Table 9-2 documents the overall nature of these key interfaces, some of which you worked
with firsthand in Chapter 8.
323