Generic Swap : Generic Function « Generics « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net » Generics » Generic Function 




Generic Swap
  

Option Explicit On
Option Strict On

Module Program
  Public Function Swap(Of T)(ByRef a As T, ByRef b As TAs T
    Console.WriteLine("T is a {0}.", GetType(T))
    Dim temp As T
    temp = a
    a = b
    b = temp
  End Function
  Sub DisplayBaseClass(Of T)()
    Console.WriteLine("Base class of {0} is: {1}.", GetType(T), GetType(T).BaseType)
  End Sub
  Sub Main()
    Dim a, b As Integer
    a = 10 : b = 40
    Swap(Of Integer)(a, b)
    Dim s1, s2 As String
    s1 = "Generics" : s2 = "Rock"
    Swap(Of String)(s1, s2)
    Dim b1, b2 As Boolean
    b1 = True : b2 = False
    Swap(b1, b2)
    DisplayBaseClass(Of Boolean)()
    DisplayBaseClass(Of String)()
    DisplayBaseClass(Of Integer)()
  End Sub
End Module

   
    
  














Related examples in the same category
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.