Chapter 7: Collections


Anyone who has been around the coding world for any length of time has more than likely written her own collection routine—probably a simply linked list. Newer programmers may not have written one of their own, but instead, in the case of C++ programmers, used the Standard Template Library (STL) version of a link list. Either way, most programmers have found a need to work with collections. The .NET Framework uses collections as well. Because collections are so common, the .NET Framework class library provides a large number of different types.

The .NET Framework class library divides its generic collections into two different namespaces. The more common collections are in the System::Collections namespace. Those collections that are specialized or less common are in the System::Collections::Specialized namespace. Something to be aware of is that the two namespaces seem to imply that the specialized collections are inherited from the common, but in fact there is no such relationship. The namespaces are just groupings of different types of collections.

This chapter will focus on the generic collection set shown in Table 7-1. However, the .NET Framework class library has many other specific collections scattered throughout the many namespaces—for example, System::Text::RegularExpressions::Group, System::Web::UI::WebControls::DataKeyCollection, System::Security::PermissionSet, and even System::Array.

Table 7-1: .NET Collection Classes




An array that grows dynamically


An array of bit values (either 1 or 0)


A small collection that will represent Boolean or small integers within 32 bits of memory


An abstract base class for deriving strongly typed collections


An abstract base class for deriving strongly typed collections of key/value pairs


A collection of key/value pairs organized based on a hash code of the key


A collection that switches from a ListDictionary when small, to a Hashtable when large


A singular link list recommended for lists of ten objects or less


A collection string of key/value pairs organized on the string key and accessible by either string key or index


A collection of first-in-first-out objects


A collection of key/value pairs sorted by key and accessible by either key or index value


A collection of first-in-last-out objects


A collection of strings


A Hashtable with the key strong typed to be a string

To make things easier for the developer, the .NET Framework class library provides a number of interfaces (see Table 7-2) that help provide some commonality between the collections. Learning collections is simplified because many of the collections share these interfaces, and once you learn an interface in one collection, it requires little effort to learn it in a second one.

Table 7-2: .NET Collection Interfaces




Defines methods to determine the size of and enable thread safety for the collection


Exposes a method to compare objects of the collection


Defines methods to allow access to key/value pairs within the collection


Exposes methods to access keys and values while enumerating a collection


Exposes a method to retrieve an object that implements the IEnumerator interface


Exposes a method to enumerate through a collection


Exposes a method to provide a custom hash algorithm


Defines methods to add, insert, delete, and access objects using an index

Managed C++ and. NET Development
Managed C++ and .NET Development: Visual Studio .NET 2003 Edition
ISBN: 1590590333
EAN: 2147483647
Year: 2005
Pages: 169 © 2008-2017.
If you may any questions please contact us: