Imports System.Collections.Generic Module Module1 Public Class Generics(Of T) 'Generic class Public Sub Swap(Of K)(ByRef lhs As K, ByRef rhs As K) 'Generic method Console.WriteLine("You sent the Swap() method a {0}", GetType(K)) Dim temp As K 'Local generic data type temp = lhs lhs = rhs rhs = temp End Sub 'Displays the data type and its base type Public Sub DisplayBaseClass(Of K)() Dim i As Type i = GetType(K) Console.WriteLine("Base class of {0} is: {1}.", i, i.BaseType) End Sub End Class Sub Main() 'Service 'Adding two integars Dim g As Generics(Of Integer) = New Generics(Of Integer) Dim a As Integer = 2 Dim b As Integer = -20 Console.WriteLine("Before swap: {0} , {1}", a, b) g.Swap(a, b) Console.WriteLine("After swap: {0} , {1}", a, b) g.DisplayBaseClass(Of Integer)() 'Adding two strings Dim gb As Generics(Of String) = New Generics(Of String)() Dim strA As String = "Hello", strB = "David" Console.WriteLine(vbCrLf + "Before swap: {0} {1}", strA, strB) g.Swap(strA, strB) Console.WriteLine("After swap: {0} {1}", strA, strB) g.DisplayBaseClass(Of String)() Console.Read() End Sub End Module