If 2 variables of the type "object", which are Int32 and Int64, are compared, "true" is displayed in Visual Studio. If I save this in a variable, it suddenly changes to "false". I have already tried the EqualityComparer. The values remain unchanged.
int number1 = 2;
long number2 = 2;
object object1 = number1;
object object2 = number2;
var equals1 = number1 == number2; // true
var equals2 = object1 == object2; // object1 == object2 is true, equals2 is false

Why is that?
EDIT:

int == long, the compiler works out that there's a conversion from int to long, and inserts code to do this. When both sides areobject, the compiler can't do this. There's nothing in the runtime which can take to integer types and figure out whether they can both be converted to a common type. If you know that one of the numbers is an int and the other is a long you can do this conversion yourself:Convert.ToInt64(object1) == Convert.ToInt64(object2)EqualityComparerwill already be doing what the answer in the dup says to do, and that doesn't work because OP's working with two boxed integer types which aren't necessarily the same type. Voting to re-open.<boxed int> == <boxed int>, not<boxed int> == <boxed long>