Re: sort problem sorting a generic list



Ok thanks it works, just using an artificial row number. Guessing that
reflection based comparer's/sorter's can have an impact on performance.
--
Paul G
Software engineer.


"sloan" wrote:


http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!141.entry

That is a 1.1 article, however, there are a few 2.0 hints at the bottom.
having said that, I would keep away from the reflection based
comparer's/sorter's .... if I had any signficant sized lists.


..........


"sloan" <sloan@xxxxxxxxx> wrote in message
news:ejcvx61DJHA.1832@xxxxxxxxxxxxxxxxxxxxxxx

You understand the concept, so now you have to find your solution.

If a two way tie isn't enough, then go to something else.

In my example...
LastName
FirstName

If I find out I have a bunch of "John Smith"'s in my collection, then I
could go to the SSN or something.

...........

If you're using an IDataReader or something like that to populate, then
yes, you can can add an artificial "RowNumber" property if you want.
Its your call. The bottom line is that if you have a tie, you can't
predict the results unless you break the tie.


Good luck.




"Paul" <Paul@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5EB9E9D8-2D52-4BD3-8122-FD1D6CF28427@xxxxxxxxxxxxxxxx
Hi thanks for the response. I made the modification as suggested. I do
not
have a row number but thinking I may need to add one and then if tie
condition have it sort on the row number. What I have below .Count is
always
0 for all records so it still is mixing things up.
Thanks again

public int CompareTo(UserDefinedGroupSummary other)
{
int returnValue = 0;//added
returnValue=GroupNumber.CompareTo(other.GroupNumber);
if (returnValue == 0)
{
returnValue = this.Count.CompareTo(other.Count);//tie
}
return returnValue;
//orig return GroupNumber.CompareTo(other.GroupNumber);

}
--
Paul G
Software engineer.


"sloan" wrote:



Here is a sample of my LastName/FirstName sorter for a User object.


returnValue = this.LastName.CompareTo(other.LastName);

if (returnValue == 0) //tie

{

returnValue = this.FirstName.CompareTo(other.FirstName);

}

return returnValue ;


Same concept.......




"Paul" <Paul@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B2850647-049F-45B0-A1AE-CE149CB814B8@xxxxxxxxxxxxxxxx
Hi, I have a generic list and am able to sort it using the code below
that
I
have built in a class UserDefinedGroupSummary. There is an integer in
the
class called GroupNumber and the sort by group number does return a
list
with
the group numbers sorted. The problem is when there is only one group
number
in the list, it looks like it is still changing the order of the
elements
in
the list.
Any ideas, thanks.

I use grouplist.Sort();// to sort the group generic list

In the class I have
public static Comparison<UserDefinedGroupSummary> CompareGroup =
delegate(UserDefinedGroupSummary g1, UserDefinedGroupSummary g2)
{
return g1.GroupNumber.CompareTo(g2.GroupNumber);
};
#region IComparable<UserDefinedGroupSummary> Members

public int CompareTo(UserDefinedGroupSummary other)
{
return GroupNumber.CompareTo(other.GroupNumber);
}
#endregion
--
Paul G
Software engineer.








.



Relevant Pages

  • Spam to read
    ... I started getting money in the mail! ... You are in the business of developing Mailing Lists. ... HOW TO POST TO NEWSGROUPS, ... that "Apostle Paul" is a self-proclaimed apostle and a liar. ...
    (soc.culture.filipino)
  • Re: PaulD - please help!
    ... Paul for replying and giving such detailed instructions - they are ... wanted to create a drop-down of vendors in the vendor heading and then a list ... cascading combo box type layout (found the synchronize two drop-down lists ... Then make selection from second box and have ...
    (microsoft.public.access.dataaccess.pages)
  • Re: cause webpage one to reload when webpage two is closed.
    ... Paul G ... Software engineer. ... one webpage to reload when a second web page is closed. ... you are using Master page and it means you should change a BODY ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: changing folder name
    ... Software engineer. ... "Paul" wrote: ... map it to a physical folder outside the application root and store the ... am allowing users to store files that are associated with a report. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: can javascript do this
    ... when moving items back to the original listbox it does not preserve ... Paul G ... Software engineer. ... sure how often they update the toolkit with new ajax controls but I may ...
    (microsoft.public.dotnet.framework.aspnet)

Loading