Using CompareTo() on different .NET types (e.g. int vs. double)

Posted by Yossin on Stack Overflow See other posts from Stack Overflow or by Yossin
Published on 2010-03-08T10:26:50Z Indexed on 2010/03/08 10:51 UTC
Read the original article Hit count: 186

Filed under:
|
|
|
|

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

© Stack Overflow or respective owner

Related posts about compareto

Related posts about .NET