Mega Code Archive

 
Categories / VB.Net / Data Structure
 

Sorts a section of the Array pair using the reverse case-insensitive comparer

Imports System Imports System.Collections Public Class SamplesArray    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 Shared Sub Main()       Dim myKeys As [String]() =  {"red", "green", "yellow"}       Dim myValues As [String]() =  {"RED", "GREEN", "YELLOW"}       Dim myComparer = New myReverserClass()       PrintKeysAndValues(myKeys, myValues)       Array.Sort(myKeys, myValues, 1, 3, myComparer)       Console.WriteLine("After sorting a section of the Array using the reverse case-insensitive comparer:")       PrintKeysAndValues(myKeys, myValues)    End Sub    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