I need to compare two variables to find if they are the same. These variables are passed as an “object” and can be assigned to any type of .NET.
The problem I am facing is if they are both numbers. In situations where they have the same value (for example, they are -1), but have different types (for example, one of them is Int32, the other is Int64), then object.Equals returns false.
Is there a reasonable general way to compare values that ignore the type of a variable and only look at a numeric value?
source
share