Chapter 4. Building Strongly Typed Collections with Generic Classes

In This Chapter

Working with the generic List class

Employing the generic LinkedList class

Using the generic Dictionary class

Sorting associations with the SortedDictionary

Stacking and queuing typed data

Starting with .NET 2.0, Microsoft gave us a new type of collection class called a generic collection. They call it that, anyway. But as you get acquainted with “generic” collections, you might think the name is a misnomer. After all, the idea behind those collections is to give you a way to create specialized containers. (Whoa! That definitely makes “generic” seem like a misnomer of the first degree.)

However, the name makes sense. Microsoft has given us mortals a set of starting points that lets us create collections that hold specific types of data, and only the specific types we tell the collection to hold. These collections are highly specialized — but their starting points are generic; you can use them to create all sorts of specialized classes. Generic starting points make highly specialized results easier to achieve; it makes sense in a warped sort of way.

To make generic collections work, however, Microsoft also had to give us something more. Microsoft has enhanced the C# and VB.NET languages by adding some syntax that goes along with the creation of the generic classes. When you create a specialized collection based on the generic classes, you specify the type of data the collection will hold. With the previous ...

Get ASP.NET 2.0 All-In-One Desk Reference For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.