Generic Types

Example generic class

Class Container<T>
    Method Add(item As T)
        Dim temp As T
    End Method
End Class

Eligible elements

You can define and use generic classes, structures, traits, and procedures. Be aware that the ViviFire standard libraries provide many commonly used generic elements that you can use in your code.

Even though procedures are not types, you can define and use generic procedures. See Generic Procedures for details.

Advantages of generic types

Constraints

Example of a constraint

Types of constraints

There are five types of constraints.

If you need to specify more than one requirement, you can put a comma between each one. Alternatively, you can use multiple Where clauses, each one on its own line.

See Where Clause (Generics) for more information.

Example of multiple constraints

Class MyClass<T> Where T Is Class Does Comparable Constructor()
    ' Class members go here
End Class
Class MyClass<T>
    Where T Does Comparable, T Is Class, T Constructor()
    ' Class members go here
End Class
Class MyClass<T>
    Where T Does Comparable
    Where T Is Class
    Where T Constructor()
    ' Class members go here
End Class