Original Post
🔒 Locked
[.net] ArrayList.Sort() Function
Advertisement
With Sort(), you are allowed to specify your own comparison class (it must be of type IComparer). So, if you would like to compare something in custom fashion just make an IComparer class (or use an existing one) that contains its own Compare() method that will compare two objects however you like.
Quote:
Is there a method for an arraylist to sort by biggest values first?
It DOES sort by the biggest value first, dude.
String sorting does not care what your string contains, semantically. It is sorting char by char bachar.
9998 Rob
is larger than
94 Rob
in the second char. That is it.
If you want sensible sorting then:
* Either padd the values with 0 or, better,
* store objects (classes) containing the numeric value as integer or something, and the string and then implement a comparer that only compares the numeric values.
Right now it does exactly what you ask it to do. Not a syntactical, but a semantical error - you do not know what you want, from the computer's point of view.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement