Imports System
Imports System.Collections
Public Class myReverserClass
Implements IComparer
Function Compare(x As [Object], y As [Object]) As Integer Implements IComparer.Compare
Return New CaseInsensitiveComparer().Compare(y, x)
End Function
End Class
Public Class SamplesArray
Public Shared Sub Main()
Dim myKeys As [String]() = {"red", "GREEN", "YELLOW", "BLUE", "purple", "black", "orange"}
Dim myValues As [String]() = {"strawberries", "PEARS", "LIMES", "BERRIES", "grapes", "olives", "cantaloupe"}
Dim myComparer = New myReverserClass()
Array.Sort(myKeys, myValues, 1, 3)
PrintKeysAndValues(myKeys, myValues)
Array.Sort(myKeys, myValues, 1, 3, myComparer)
PrintKeysAndValues(myKeys, myValues)
Array.Sort(myKeys, myValues)
PrintKeysAndValues(myKeys, myValues)
Array.Sort(myKeys, myValues, myComparer)
PrintKeysAndValues(myKeys, myValues)
End Sub 'Main
Public Shared Sub PrintKeysAndValues(myKeys() As [String], myValues() As [String])
Dim i As Integer
For i = 0 To myKeys.Length - 1
Console.WriteLine(" {0,-10}: {1}", myKeys(i), myValues(i))
Next i
End Sub
End Class
|