By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,529 Members | 1,826 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,529 IT Pros & Developers. It's quick & easy.

result of List.Sort on already elements with same value.

P: n/a
I have a generic list with a some objects of a particular class in it.
I have implemented a IComparer for the the class and pass it to the
The list.sort method works fine when the value of the field I want to
compare is different, but when all the elements are same, the list
still gets sorted(meaning the sequence of the elements still change).
For eg.
Say the list is filled with object of type A, where in A has a
property index. The Icomparer which I pass to the list compares this
property and returns appropriate value.

Now if the list contains 4 objects with the value in their index field
as 1,2,3,4, then the list.sort works fine and arranges the elements in
the proper order (asc or desc).
But if the value in the index field is the same ie. 1,1,1,1, then
ideally when I call the list.sort method the sequence of the elements
should not change. But it changes...
can some one help me here.... Also the Comparer works fine, I debugged
and every time it returns the value 0 for compareto method if the
values being compared as same.
this is a problem for me because the Class that I am using has
multiple fields, and the user should be able to sort the list based on
any of this field.I have developed an appropriate comparer for the
same, and it works fabulously, except when the value are the same...

Say for eg my class contains two fields 'UserID' and 'Age'.
now if I sort the list according to the userid, the list gets sorted
Say no all the user have the same age. so if I sort the list using the
Age field the list should not get changed, but it does...I think its
cause of the quick sort..

Please help Me..............

May 12 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.