Re: sort problem sorting a generic list
- From: Paul <Paul@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 8 Sep 2008 09:32:12 -0700
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.
- References:
- sort problem sorting a generic list
- From: Paul
- Re: sort problem sorting a generic list
- From: sloan
- Re: sort problem sorting a generic list
- From: Paul
- Re: sort problem sorting a generic list
- From: sloan
- Re: sort problem sorting a generic list
- From: sloan
- sort problem sorting a generic list
- Prev by Date: Visual Studio 2008 - Master Page Error
- Next by Date: Deploying service tier resources and referencing their filepath
- Previous by thread: Re: sort problem sorting a generic list
- Next by thread: Re: Two ContentPlaceHolders in the MasterPage
- Index(es):
Relevant Pages
|
Loading