Sometimes you’re going to need a data structure that is an array of classes and you’re going to want to sort them. The standard array Sort method can only sort simple types (Text, Integer, etc), so what do you do?
The traditional technique has been to use SortWith. You create a separate array of a simple type, populate it and then sort the temporary array using SortWith to sort the class array.
But there is an even slicker way to sort that was added in 2015 Release 3. You can now create your own custom comparison method and use that to sort the class. This custom method returns 0 if the values to compare are equal, a positive if the first value is greater than the second, and a negative value if the first value is less than the second.
Comments closed