Creating and Consuming Generics

Creating a generic type is accomplished by providing a parameterized type definition. The following is an example:


The Of keyword is followed by the type that the new object can handle. T is the type parameter and represents the .NET type that you want to be held by your generic type. The type parameter’s name is left to your own choosing, but you often find T as a common name in the .NET Framework base class library. At this point you must write code to manipulate the T type in a way that will be convenient for possibly every .NET type. Now imagine you want to build a custom collection that you want to reuse ...

Get Visual Basic 2010 Unleashed now with O’Reilly online learning.

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