← Back to home

Templates in Visual Basic

For those of you still complaining about the introduction of Generics in Java, know that Visual Basic will have Generics as well in Whidbey (the next version of Visual Studio):

Class MyCollection(Of ElementType)
Sub Add(Byval key As String, Byval Element As ElementType)
'Note that the type parameter ElementType is being used inside
'the generic type just like any other type
'
Dim Element2 As ElementType
...
End Sub
...
End Class
Dim IntegerCol As New MyCollection(Of Integer)
Dim DateCol As New MyCollection(Of Date)

Needless to say this beast bears very little resemblance with the Basic of my childhood (Applesoft Basic).

Comments (2)

Merrick

Your example is the normal form we get today. The generic version is slightly more obfuscated: Sub Sort(Of T)(Byval Arr() As T) ... End Sub.

Robert Watkins

This isn't really surprising; VB.NET is really just a syntatic translation of C#. Makes you wonder why they bothered...