O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required