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

Using Generic Types

In our discussion about generic types, you learned how a generic type is used repeatedly. Let’s concentrate on the phonebook example a bit more:

var numbers = new Dictionary<string, int> {    { "Bart", 911 },    { "John", 119 }};

In the preceding code, we’re making a constructed generic type (sometimes referred to as a closed generic type) by substituting the TKey type parameter for string and the TValue type parameter for int. As you expect from a great development environment, Visual Studio provides IntelliSense when supplying types for generic type parameters, as shown in Figure 15.9.

Image

FIGURE ...

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