' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
﻿Imports System

Namespace Gen
    Public Class Pair(Of T As IComparable(Of T))
        Public Property FirstValue() As T
        Public Property SecondValue() As T
        Public Sub New(first As T, second As T)
            FirstValue = first
            SecondValue = second
        End Sub
        Public Sub Swap()
            Dim temp As T = FirstValue
            FirstValue = SecondValue
            SecondValue = temp
        End Sub
        Public Function Max() As T
            If FirstValue.CompareTo(SecondValue) > 0 Then
                Return FirstValue
            Else
                Return SecondValue
            End If
        End Function
        Public Overrides Function ToString() As String
            Return String.Format("({0},{1})", FirstValue, SecondValue)
        End Function
    End Class
    Public Class Program
        Public Shared Sub Main(args As String())
            Dim ip As New Pair(Of Integer)(123, 456)
            Console.WriteLine(ip)
            Console.WriteLine(ip.Max())
            ip.Swap()
            Console.WriteLine(ip)
            Console.WriteLine(ip.Max())
            Dim sp As New Pair(Of String)("ABC", "DEF")
            Console.WriteLine(sp)
            Console.WriteLine(sp.Max())
            sp.Swap()
            Console.WriteLine(sp)
            Console.WriteLine(sp.Max())
            Console.ReadKey()
        End Sub
    End Class
End Namespace
