The .NET Framework 2.0 introduces generics to allow you to create flexible, reusable code. Language features collectively known as generics act as templates that allow classes, structures, interfaces, methods, and delegates to be declared and defined with unspecified or generic type parameters instead of specific types. Actual types are specified later when the generic is used. The new System.Collections.Generic namespace provides support for strongly typed collections. System.Nullable is a standard representation of optional values.
Use generic types to maximize code reuse, type safety, and performance. The most common use of generics is to create collection classes. You can create your own generic interfaces, classes, methods, events and delegates. Generic classes may be constrained to enable access to methods on particular data types.
E.g.
Stack - Represents a variable size last-in-first-out(LIFO) collection of instances of the same arbitrary type.
Stack numbers = new Stack();
numbers.Push("One");
numbers.Push("Two");
numbers.Push("Three");
numbers.Push("Four");
// A stack can be enumerated without disturbing its contents.
foreach (string number in numbers)
{
Console.WriteLine(number);
}
Information on the types used in a generic data type may be obtained at run-time by means of reflection.