July 09, 2004

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).

Posted by cedric at July 9, 2004 06:45 AM
Comments

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.

Posted by: Merrick at July 9, 2004 07:59 AM

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

Posted by: Robert Watkins at July 13, 2004 04:47 AM
Post a comment






Remember personal info?