Mega Code Archive

 
Categories / VB.Net / Data Structure
 

Sorts the elements in the ArrayList using the specified comparer

Imports System Imports System.Collections Imports Microsoft.VisualBasic Public Class SamplesArrayList    Public Class myReverserClass       Implements IComparer       Public Function Compare( ByVal x As Object, ByVal y As Object) As Integer _          Implements IComparer.Compare          Return New CaseInsensitiveComparer().Compare(y, x)       End Function     End Class    Public Shared Sub Main()       Dim myAL As New ArrayList()       myAL.Add("A")       myAL.Add("B")       myAL.Add("C")       myAL.Add("D")       PrintIndexAndValues(myAL)       myAL.Sort()       PrintIndexAndValues(myAL)       Dim myComparer = New myReverserClass()       myAL.Sort(myComparer)       PrintIndexAndValues(myAL)    End Sub    Public Shared Sub PrintIndexAndValues(myList As IEnumerable)       Dim i As Integer = 0       Dim obj As [Object]       For Each obj In  myList          Console.WriteLine(vbTab + "[{0}]:" + vbTab + "{1}", i, obj)          i = i + 1       Next obj    End Sub End Class