For those of you not familiar with operator overloding,
you can overload operators for custom classes and structures.
Here is a example overloading the + operator
public class Point
{
public double X { get; set; }
public double Y { get; set; }
public Point(double x, double y)
{
X = x;
Y = y;
}
public static Point operator +(Point p1, Point p2)
{
return new Point(p1.X + p2.X, p1.Y + p2.Y);
}
}
You could implement IComparable and do something like this for Comparison operators
public class Point: IComparable
{
public double X { get; set; }
public double Y { get; set; }
public Point(double x, double y)
{
X = x;
Y = y;
}
public static Point operator +(Point p1, Point p2)
{
return new Point(p1.X + p2.X, p1.Y + p2.Y);
}
public int CompareTo(object obj)
{
Point pnt = (Point)obj;
if (this.X > pnt.X && this.Y > pnt.Y)
{
return 1;
}
else if (this.X < pnt.X && this.Y < pnt.Y)
{
return -1;
}
else
{
return 0;
}
}
public static bool operator <=(Point p1, Point p2)
{
return (p1.CompareTo(p2) <= 0);
}
public static bool operator <(Point p1, Point p2)
{
return (p1.CompareTo(p2) < 0);
}
}
And here is the function that Bill posted decompiled From System.DateTime
public static bool operator <=(DateTime t1, DateTime t2)
{
return &t1.InternalTicks <= &t2.InternalTicks;
}