Required. Name of the type parameter. This is a placeholder, to be replaced by a defined type supplied by the corresponding type argument.

constraintlist

Optional. List of requirements that constrain the data type that can be supplied for typename. If you have multiple constraints, enclose them in curly braces ({ }) and separate them with commas. You must introduce the constraint list with the As keyword. You use As only once, at the beginning of the list.

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.

Rules

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 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 keyword or the Structure keyword. The Class keyword constrains a generic type parameter to require that any type argument passed to it be a reference type, for example a string, array, or delegate, or an object created from a class. The Structure keyword constrains a generic type parameter to require that any type argument passed to it be a value type, for example a structure, enumeration, or elementary data 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.

Behavior

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.

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.