The most prevalent use of generics in any language is in the area of collections. Collections deal with sets of like objects and with managing those objects as a group. This chapter looks at the collection classes provided with the runtime and how you use them within your applications. It also covers the various collection interfaces and how they relate to each other, and it includes a discussion of how to create custom collections using iterators. This C# 2.0 feature simplifies implementation of how the foreach statement iterates over the elements in a collection. Iterators not only encapsulate the internal data structure of your collection classes, but they also improve control over end-user access and the use of data within a collection.
There are two types of collection-related classes: those that support generics and those that don't. This chapter primarily discusses the generic collection classes. Generally, you should use collection classes that don't support generics only when writing components that need to interoperate with earlier versions of the runtime. This is because everything that was available in the nongeneric form has a generic replacement that is strongly typed.