J
Jon Slaughter
public class PointSorter : IComparer<PointF>
{
int IComparer<PointF>.Compare(PointF x, PointF y)
{
if (x.X > y.X)
return 1;
if (x.X < y.X)
return -1;
return 0;
}
} IComparer<PointF> pointSorter = new PointSorter();
..... Later...
Array.Sort<PointF>(data, pointSorter);
So this code lets me sort a point array based on the x values. Is there any
way to shorten this code? I realize that its pretty short as is but seems
like way to much overkill just to do a simple sort on a "compound" object.
What would be nice is some anonymous comparators
I'm also not sure if generics are needed here or not but the code works and
thats what I did.
Thanks,
Jon
{
int IComparer<PointF>.Compare(PointF x, PointF y)
{
if (x.X > y.X)
return 1;
if (x.X < y.X)
return -1;
return 0;
}
} IComparer<PointF> pointSorter = new PointSorter();
..... Later...
Array.Sort<PointF>(data, pointSorter);
So this code lets me sort a point array based on the x values. Is there any
way to shorten this code? I realize that its pretty short as is but seems
like way to much overkill just to do a simple sort on a "compound" object.
What would be nice is some anonymous comparators
I'm also not sure if generics are needed here or not but the code works and
thats what I did.
Thanks,
Jon