I am trying to use an IComparer
to sort a list of Points. Here is the IComparer class:
public class CoordinatesBasedComparer : IComparer
{
public int Compare(Object q, Object r)
{
Point a = (p)q;
Point b = (p)r;
if ((a.x == b.x) && (a.y == b.y))
return 0;
if ((a.x < b.x) || ((a.x == b.x) && (a.y < b.y)))
return -1;
return 1;
}
}
In the client code, I am trying to using this class for sorting a list of points p (of type List<Point>
):
CoordinatesBasedComparer c = new CoordinatesBasedComparer();
Points.Sort(c);
The code errors out. Apparently it is expecting IComparer<Point>
as argument to sort method.
What do I need to do to fix this?