Sveučilište u Zagrebu  |  Filozofski fakultet  |  Služba za informatiku  |  links


System.Comparison(Of T) Sample


For a collection to be sortable, you must ensure one of this:

1) each object in a collection implements IComparable interface (=
   a class implements an instance CompareTo() function, which 
   compares current object to another one, given as a parameter
   to a CompareTo() function)


2) a System.Comparison (function) delegate is supplied to a sorting 
   procedure; this function compares two parameters.

   myList.Sort(Function(a, b) a.CompareTo(b))

3) an object that implements IComparer interface is supplied to a 
   sorting procedure; to implement IComparer interface, a class has to
   have instance CompareTo() function that compares two parameters.

   myList.Sort(new IComparerClass())

Each of these functions returns -1 if the first parameter is smaller/earlier,
0 if arguments are equal and 1 if the second one is smaller/earlier.

komentare molim ovdje