Creating and Consuming Generics

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

image

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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.