> Sorts great!...but in only one direction.
>
> We would like to have the list descending as well.
>> Sorts great!...but in only one direction.
>>
[quoted text clipped - 4 lines]
> usually more like 3 or 4), and overloaded sort functions can take them as
> arguments.
The code looks like:
private void DoSomething()
{
List<string> foo = new List<string>();
foo.Add("a");
foo.Add("b");
foo.Add("z");
foo.Add("e");
foo.Add("j");
foo.Sort(new StringReverseComparer());
MessageBox.Show(foo[0]);
}
public class StringReverseComparer : IComparer<string>
{
public virtual int Compare(string x, string y)
{
return x.CompareTo(y) * -1;
}
}
The framework already has all the relevant comparers for the basic types, so
this isn't something you would normally do for a string collection, but the
point is valid for any generic type.

Signature
Chris Mullins
Sean - 02 Mar 2006 02:09 GMT
Thanks I will look more into that code you wrote.
> >> Sorts great!...but in only one direction.
> >>
[quoted text clipped - 30 lines]
> this isn't something you would normally do for a string collection, but the
> point is valid for any generic type.
tommaso.gastaldi@uniroma1.it - 02 Mar 2006 14:07 GMT
I wouldn't even bother to wate time in the multiplication (for -1). It
should be sufficient to reverse operands in the compare ;-)
-tom
> public class StringReverseComparer : IComparer<string>
> {
[quoted text clipped - 7 lines]
> this isn't something you would normally do for a string collection, but the
> point is valid for any generic type.