Specifies the type parameters for a generic programming element. Multiple parameters are separated by commas. Following is the syntax for one type parameter.
Every generic programming element must take at least one type parameter. A type parameter is a placeholder for a specific type (a constructed element) that client code specifies when it creates an instance of the generic type. You can define a generic class, structure, interface, procedure, or delegate.
Parentheses. If you supply a type parameter list, you must enclose it in parentheses, and you must introduce the list with the Of keyword. You use Of only once, at the beginning of the list.
Constraints. A list of constraints on a type parameter can include the following items in any combination:
Any number of interfaces. The supplied type must implement every interface in this list.
At most one class. The supplied type must inherit from that class.
The New (Visual Basic) keyword. The supplied type must expose a parameterless constructor that your generic type can access. This is useful if you constrain a type parameter by one or more interfaces. A type that implements interfaces does not necessarily expose a constructor, and depending on the access level of a constructor, the code within the generic type might not be able to access it.
Either the Class (Visual Basic) keyword or the Structure (Visual Basic) keyword. If you include Class, the supplied type must be a reference type. If you include Structure, the supplied type must be a value type. You cannot include both Class and Structure in the same constraintlist.
The supplied type must satisfy every requirement you include in constraintlist.
Constraints on each type parameter are independent of constraints on other type parameters.
Compile-Time Substitution. When you create a constructed type from a generic programming element, you supply a defined type for each type parameter. The Visual Basic compiler substitutes that supplied type for every occurrence of typename within the generic element.
Absence of Constraints. If you do not specify any constraints on a type parameter, your code is limited to the operations and members supported by the Object Data Type for that type parameter.
The following example shows a skeleton definition of a generic dictionary class, including a skeleton function to add a new entry to the dictionary.
Because dictionary is generic, the code that uses it can create a variety of objects from it, each having the same functionality but acting on a different data type. The following example shows a line of code that creates a dictionary object with String entries and Integer keys.
The following example shows the equivalent skeleton definition generated by the preceding example.