Using CompareTo() on different .NET types (e.g. int vs. double)
- by Yossin
Hi,
I've got a static method that accepts two object type variables and runs the CompareTo() method:
public static int Compare(Object objA, Object objB)
{
return (((IComparable)objA).CompareTo(objB));
}
Problem is that CompareTo() throws an exception when trying to compare between different types (e.g. int and double).
Does any one know of a better way in C#, to compare between two different types?
Or a workaround to this problem?
Thanks