A Note on Generics

The second version of the CLI introduced support for generics, a way to make types and members dependent on a certain type of parameter. In the type theory literature this is known as parametric polymorphism. Typical applications of generics include the definition and use of collection types:

var primes = new List<int> { 2, 3, 5, 7 };int firstPrime = primes[0];

In the preceding example, we’re using a generic collection type List<T>, where T has been substituted for int. Similarly, we could construct specialized list types to contain strings, Customer objects, or whatever else we see fit (including lists of lists). The use of generics makes static typing possible in many more cases than before, ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.