Out (Generics)

Specifies that a type parameter is covariant.


Covariance lets you use a child class of the class specified by a generic parameter. This permits automatic conversion of classes that implement variant traits and automatic conversion of event types. See Covariance and Contravariance for more information.


You can use the modifier Out with generic traits and events.

In a generic trait, you can declare a type parameter as covariant if you obey the instructions that follow:


' Covariant trait.
Trait TCovariant[Out T]
End Trait

' Extending covariant trait.
Trait TExtCovariant[Out T] Does TCovariant[T]
End Trait

' Implementing covariant trait.
Class Sample[T] Does TCovariant[T]
End Class

Var parent As TCovariant[CParent] = CSample[CParent]
Var child As TCovariant[CChild] = CSample[CChild]

' You can assign child to parent because
' the TCovariant trait is covariant.
parent = child

Applies to

See also