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

A

Amar

Hi,
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
List.
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
perfectly.
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..............
 
G

Guest

Hi Amar

I am facing the same problem as well, except that the results seem to be
different in .net 1.1 and .net 2.0. Did you manage to solve this problem?

In .net 1.1 lets say I get an output as below for items having the same value

A
B
C

In .net 2.0 i am getting
C
B
A

This is driving me crazy!! .. please do let me know if you have overcome this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top