The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Generic Methods...

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Duncan Mackenzie

Posts: 689
Nickname: duncanma
Registered: Aug, 2003

Duncan Mackenzie is the Visual Basic Content Strategist at msdn.microsoft.com
Generic Methods... Posted: Mar 20, 2004 12:33 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Duncan Mackenzie.
Original Post: Generic Methods...
Feed Title: Code/Tea/Etc...
Feed URL: /msdnerror.htm?aspxerrorpath=/duncanma/rss.aspx
Feed Description: Duncan is the Visual Basic Content Strategist at MSDN, the editor of the Visual Basic Developer Center (http://msdn.microsoft.com/vbasic), and the author of the "Coding 4 Fun" column on MSDN (http://msdn.microsoft.com/vbasic/using/columns/code4fun/default.aspx). While typically Visual Basic focused, his blogs sometimes wanders off of the technical path and into various musing of his troubled mind.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Duncan Mackenzie
Latest Posts From Code/Tea/Etc...

Advertisement
Someone suggested to me that VB.NET Whidbey didn't have support for 'Generic Methods', so I quickly wrote a bit of sample code to check (yes, it does support Generic Methods) and I thought I'd post that test code for your amusement.
Public Class GenericMethodSample
    Public Sub Swap(Of T)(ByRef i As T, ByRef j As T)
        Dim temp As T
        temp = j
        j = i
        i = temp
    End Sub
End Class

Public Class Sample

    Public Sub TestSwap()
        Dim i, j As Integer
        i = 3
        j = 12

        Debug.WriteLine(i)
        Debug.WriteLine(j)
        Debug.WriteLine("-------")

        Dim gm As New GenericMethodSample
        gm.Swap(Of Integer)(i, j)
        Debug.WriteLine(i)
        Debug.WriteLine(j)


    End Sub

End Class

If you need the 'blow-by-blow' explanation of that code... the key lines to notice are;
    Public Sub Swap(Of T)(ByRef i As T, ByRef j As T)

Which declares a "Generic Method", which is then strongly typed at runtime via code like this;
    gm.Swap(Of Integer)(i, j)

Read: Generic Methods...

Topic: "Geeks and the Women/Men Who Love Them" or "Normal People are from Earth, Coders are from Sedna" Previous Topic   Next Topic Topic: Windows XP Service Pack 2 Developer Training

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use