Sorts the elements in a range in an Array using the IComparable(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
Return y.CompareTo(x)
End Function
End Class
Public Class Example
Public Shared Sub Main()
Dim numbers() As String = {"Ten","Two","Three","Zero","One","Thirty" }
For Each num As String In numbers
Console.WriteLine(num)
Next
Array.Sort(numbers, 3, 3)
For Each num As String In numbers
Console.WriteLine(num)
Next
Dim rc As New ReverseComparer()
Array.Sort(numbers, 3, 3, rc)
For Each num As String In numbers
Console.WriteLine(num)
Next
End Sub
End Class
Related examples in the same category