Generic Collections in the .NET Framework
This topic provides an overview of the generic collection classes and other generic types in the .NET Framework.
The .NET Framework class library provides a number of generic collection classes in the System.Collections.Generic and System.Collections.ObjectModel namespaces. For more information about these classes, see Commonly Used Collection Types.
Many of the generic collection types are direct analogs of nongeneric types. Dictionary is a generic version of Hashtable; it uses the generic structure KeyValuePair for enumeration instead of DictionaryEntry.
There are generic and nongeneric versions of SortedList. Both versions are hybrids of a dictionary and a list. The SortedDictionary generic class is a pure dictionary and has no nongeneric counterpart.
The LinkedList generic class is a true linked list. It has no nongeneric counterpart.
The Collection generic class provides a base class for deriving your own generic collection types. The ReadOnlyCollection class provides an easy way to produce a read-only collection from any type that implements the IList generic interface. The KeyedCollection generic class provides a way to store objects that contain their own keys.
The Nullable generic structure allows you to use value types as if they could be assigned null. This can be useful when working with database queries, where fields that contain value types can be missing. The generic type parameter can be any value type.
In C# it is not necessary to use Nullable explicitly because the language has syntax for nullable types.
The ArraySegment generic structure provides a way to delimit a range of elements within a one-dimensional, zero-based array of any type. The generic type parameter is the type of the array's elements.
The EventHandler generic delegate eliminates the need to declare a delegate type to handle events, if your event follows the event-handling pattern used by the .NET Framework. For example, suppose you have created a MyEventArgs class, derived from EventArgs, to hold the data for your event. You can then declare the event as follows: