' 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
Imports System.Collections

Namespace E
    Public Class MyData
        Private _v As Integer
        Private _s As String
        Public Sub New()
            MyClass.New(0, "")
        End Sub
        Public Sub New(ByVal v As Integer, ByVal s As String)
            _v = v
            _s = s
        End Sub
        Public Property V() As Integer
            Get
                Return _v
            End Get
            Set
                _v = value
            End Set
        End Property
        Public Property S() As String
            Get
                Return _s
            End Get
            Set
                _s = value
            End Set
        End Property
        Public Overloads Overrides Function ToString() As String
            Return ("(" & _v & "," & _s & ")")
        End Function
    End Class 
    Public Class MyDataComparerV
    Implements IComparer
        Function Compare(ByVal o1 As Object, ByVal o2 As Object) As Integer Implements IComparer.Compare
            Return (CType(o1, MyData).V - CType(o2, MyData).V)
        End Function
    End Class 
    Public Class MyDataComparerS
    Implements IComparer
        Function Compare(ByVal o1 As Object, ByVal o2 As Object) As Integer Implements IComparer.Compare
            Return CType(o1, MyData).S.CompareTo(CType(o2, MyData).S)
        End Function
    End Class 
    Public Class MainClass
        Public Shared Sub Main(ByVal args As String())
            Dim al As ArrayList = New ArrayList
            al.Add(New MyData(2, "A"))
            al.Add(New MyData(1, "CCC"))
            al.Add(New MyData(3, "BB"))
            Dim i As Integer
            For i = 0 To al.Count-1
                Console.WriteLine(al(i))
            Next
            al.Sort(New MyDataComparerV)
            For i = 0 To al.Count-1
                Console.WriteLine(al(i))
            Next
            al.Sort(New MyDataComparerS)
            For i = 0 To al.Count-1
                Console.WriteLine(al(i))
            Next
        End Sub
    End Class 
End Namespace
