Where Clause (Generics)

Specifies constraints to put on generic parameters.

Syntax

Where constraint [ , constraint ]…

Parts

constraint
One or more constraints to put on a generic parameter, with a comma between each.

Constraint

Long constructShort construct
[ min_limit { < | <= } ] type_parameter { < | <= } max_limit
[ min_limit { < | <= } ] type_parameter [ { < | <= } max_limit ]
type_parameter Is { Class | Struct }
[ Is { Class | Struct } ]
type_parameter Does bounding_trait
[ Does bounding_trait ]…
type_parameter Constructor ( )
[ Constructor ( ) ]
type_parameter
One of the generic parameters given in a Type List.
max_limit
The most basic class from which type_parameter can inherit.
min_limit
The most specialized class from which type_parameter can inherit.
bounding_trait
A trait that type_parameter must implement.
Is
Specifies if type_parameter must be a reference type (Is Class) or a value type (Is Struct).
Constructor
Specifies that type_parameter must supply a default constructor.

Instructions

TODO

Examples

Class Dictionary[DataType, KeyType]
  Where KeyType Does Compare Constructor()

  Method Add d As DataType, k As KeyType
  End Method
  Method Find(k As KeyType) As DataType
  End Method
End Class

Applies to

See also