Tech Off Thread

1 post

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

VB Generics

Back to Forum: Tech Off
  • User profile image

    I'm surprised how many people don't realize that we (and by we I mean VB) have full generic support in Whidbey. We can consume, author, and use constraints. I just answered an internal email where someone was wondering how this all worked and I figured this info would be useful to all you Channel9 types.
    Imports System.Collections.Generic

    Dim foo as New List(Of String)
    Dim bar as New Dictionary(Of String, String)

    Module Test
       Public Sub Foo(Of T)(ByVal param As T)
       End Sub

       Public Sub Bar()
          Dim x as String
          ' call explictly the one you want
          Foo(Of String)(x)
          ' or let the compiler do it for you
          Foo(x) ' same as above
       End Sub

    End Module

    Public Class Foo(Of G,E,N,E,R,I,C,S)
    End Class


    Public Class Foo(Of T As IEnumerable)
    End Class

    Happy Coding (especially if it's in VB Smiley)

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.