|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
Generics in the .NET Framework
Generics let you tailor a method, class, structure, or interface to the precise data type it acts upon. For example, instead of using theclass, which allows keys and values to be of any type, you can use the generic class and specify the type allowed for the key and the type allowed for the value. Among the benefits of generics are increased code reusability and type safety.
A number of generic collection classes are provided in the .NET Framework, in theand namespaces. Generic interfaces for implementing sort and equality comparisons are provided in the namespace, along with generic delegate types for event handlers, conversions, and search predicates.
Support for generics has been added tofor examining generic types and generic methods, to for emitting dynamic assemblies that contain generic types and methods, and to for generating source graphs that include generics.
Visual Basic, C#, and Visual C++ provide full support for defining and using generic types. The common language runtime provides new opcodes and prefixes to support generic types in Microsoft intermediate language (MSIL).
In This Section
Describes the Generics feature, the capabilities it brings to the .NET Framework, and the way it is exposed in the common language runtime.
Summarizes the advantages of using generics.
Catalogs most of the generic collection types provided by the .NET Framework, such as theand Dictionary generic classes.
Catalogs additional generic collection types, such as thegeneric class, that are useful for exposing object models to users of your classes.
New opcodes and prefixes have been added to support generics, including, , , , and .