CHAPTER 9 COLLECTIONS AND GENERICS
As you would guess, the ArrayList class has many useful members beyond the Count property and
AddRange() and Add() methods, so be sure you consult the .NET Framework documentation for full
details. On a related note, the other classes of System.Collections (Stack, Queue, and so on) are also fully
documented in the .NET help system.
However, it is very important to point out that a majority of your .NET projects will most likely not
make use of the collection classes in the System.Collections namespace! To be sure, these days it is far
more common to make use of the generic counterpart classes found in the System.Collections.Generic
namespace. Given this point, I won’t comment on (or provide code examples for) the remaining
nongeneric classes found in System.Collections.
A Survey of System.Collections.Specialized Namespace
System.Collections is not the only .NET namespace that contains nongeneric collection classes. For
example, the System.Collections.Specialized namespace defines a number of (pardon the
redundancy) specialized collection types. Table 9-3 documents some of the more useful types in this
particular collection-centric namespace, all of which are nongeneric.
Table 9-3. Useful Classes of System.Collections.Specialized
System.Collections.Specialized
Type
Meaning in Life
HybridDictionary
This class implements IDictionary by using a ListDictionary
while the collection is small, and then switching to a Hashtable
when the collection gets large.
ListDictionary
This class is useful when you need to manage a small number of
items (10 or so) that can change over time. This class makes use
of a singly linked list to maintain its data.
StringCollection
This class provides an optimal way to manage large collections of
string data.
BitVector32
This class provides a simple structure that stores Boolean values
and small integers in 32 bits of memory.
Beyond these concrete types, this namespace also contains many additional interfaces and abstract
base classes that you can use as a starting point for creating custom collection classes. While these
“specialized” types might be just what your projects require in some situations, I won’t comment on
their usage here. Again, in many cases, you will likely find that the System.Collections.Generic
namespace provides classes with similar functionality and additional benefits.
325