When is Compare() used?
I just realised that it might be useful to add it to some of my new date objects, but where will it be utilised? Lists, Maps ?
hmmm. I guess I should implement it and then try it and see...
It's used by any type of comparison, ie.
if m>n / m => n / m <> n / m < n / etc.
Especially useful for sorting stuff with the array.sort and list.sort methods. Maps use it as well.
Compare is used when sorting lists of types (i.e. using list.Sort() ) . The sort algorithm calls a type's method passing another type instance (to compare it to) as the parameter, and you return 1 or -1, depending on whether the object should go before or after the current instance.
Ahh... so if I have a list of Date objects that can "compare()" they could be sorted in the correct order without me worrying about having to code my own sort?
That's kind of handy :-)
Thanks !