Why is IComparable not working for you?
You cannot get syntactic sugar using "<" and ">", but you can check if the CompareTo result is less than or greater than 0, which gives you the same information.
, .
static void Main(string[] args)
{
Console.WriteLine(1.IsGreaterThan(2));
Console.WriteLine(1.IsLessThan(2));
}
public static bool IsGreaterThan<T>(this T value, T other) where T : IComparable
{
return value.CompareTo(other) > 0;
}
public static bool IsLessThan<T>(this T value, T other) where T : IComparable
{
return value.CompareTo(other) < 0;
}