Declaring Generic Types

Let’s take a closer look at how generic types are declared. We’ve already seen the syntax used, using angle brackets < and > to specify a comma-separated list of type parameters. For example, here’s another generic collection type with two type parameters:

class Dictionary<TKey, TValue>

Note: Visual Basic Syntax

When talking about generic types, use the word of to separate the name of the type from its type parameters, as denoted by angle brackets in C#. Visual Basic sounds like plain English language and uses the Of keyword to make this explicit:

Class List(Of T)    '...End Class

To construct a type out of the generic type, the same Of keyword is used, followed by the type to be substituted for the type parameter in ...

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.