Free mag vol1 | Page 400

CHAPTER 9  COLLECTIONS AND GENERICS The System.Collections.Generic namespace also defines several classes that implement many of these key interfaces. Table 9-5 describes some commonly used classes of this namespace, the interfaces they implement, and their basic functionality. Table 9-5. Classes of System.Collections.Generic Generic Class Supported Key Interfaces Meaning in Life Dictionary ICollection, IDictionary, IEnumerable This represents a generic collection of keys and values. LinkedList ICollection, IEnumerable This represents a doubly linked list. List ICollection, IEnumerable, IList This is a dynamically resizable sequential list of items. Queue ICollection (Not a typo! This is the nongeneric collection interface) , IEnumerable This is a generic implementation of a first-in, first-out (FIFO) list. SortedDictionary ICollection, IDictionary, IEnumerable This is a generic implementation of a sorted set of key/value pairs. SortedSet ICollection, IEnumerable, ISet This represents a collection of objects that is maintained in sorted order with no duplication. Stack ICollection (Not a typo! This is the nongeneric collection interface) , IEnumerable This is a generic implementation of a last-in, first-out (LIFO) list. The System.Collections.Generic namespace also defines many auxiliary classes and structures that work in conjunction with a specific container. For example, the LinkedListNode type represents a node within a generic LinkedList, the KeyNotFoundException exception is raised when attempting to grab an item from a container using a nonexistent key, and so forth. It is also worth pointing out that mscorlib.dll and System.dll are not the only assemblies that add new types to the System.Collections.Generic namespace. For example, System.Core.dll adds the HashSet class to the mix. Be sure to consult the .NET Framework documentation for full details of the System.Collections.Generic namespace. In any case, your next task is to learn how to use some of these generic collection classes. Before you do however, allow me to illustrate a C# language feature (first introduced in .NET 3.5) that simplifies the way you populate generic (and nongeneric) collection containers with data. 339