Searches sorted Array for a value using the specified IComparer(Of T) generic interface.
Imports System
Imports System.Collections.Generic
Public Class ReverseComparer
Implements IComparer(Of String)
Public Function Compare(ByVal x As String, _
ByVal y As String) As Integer _
Implements IComparer(Of String).Compare
' Compare y and x in reverse order.
Return y.CompareTo(x)
End Function
End Class
Public Class Example
Public Shared Sub Main()
Dim numbers() As String = {"Ten","Two","One","Three","Four","Nine" }
For Each num As String In numbers
Console.WriteLine(num)
Next
Dim rc As New ReverseComparer()
Array.Sort(numbers, rc)
For Each num As String In numbers
Console.WriteLine(num)
Next
Dim index As Integer = Array.BinarySearch(numbers, "One", rc)
Console.WriteLine(index)
End Sub
End Class
Related examples in the same category