Two .NET objects that are equal don't say they are
问题 I have the following code: object val1 = 1; object val2 = 1; bool result1 = (val1 == val2);//Equals false bool result2 = val1.Equals(val2); //Equals true What's up with that? Is the only way to fix this to go with .Equals() method? 回答1: The operator == is static, not virtual, so the behaviour is determined by the static type and not the runtime type. The default implementation for == on objects of reference type is to compare the references (although types can implement a different behaviour,