Overloading Type Parameters

You can overload generic definitions providing different signatures for the type parameter, similar to what happens in method overloads. The following code provides an example:

Public Class CustomTypeEnd ClassPublic Class CustomType(Of T1, T2)End ClassPublic Class CustomType(Of T As {Class, ICloneable, New})End Class

It is worth mentioning that providing a nongeneric version of your class is not necessary. You can provide different implementations for your generic types. Now consider the following overloading attempt:

Class CustomType(Of T1, T2)End Class'Fails at compile timeClass CustomType(Of T1 As IComparable, T2 As ICloneable)End Class

This code is not ...

Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.