A float equals only another float , and int equals only another int . The only lines that return true are the following:
Console.WriteLine(f.Equals(i)); Console.WriteLine(i == f);
In both cases, there is an implicit conversion of the value of i to a float , so they are equivalent:
Console.WriteLine(f.Equals((float) i)); Console.WriteLine((float) i == f);
These transformations are just normal transformations needed to resolve method and operator overloads.
None of the remaining lines include an implicit conversion, so they compare two different types, which gives a false result even when compared by value (which is the case with all Equals ). Therefore, the use of Equals in int fields returns true , because it is a comparison of two values ββof the same type by value.
In this case:
Console.WriteLine(obi == obf);
he doesn't even try to compare numerical values ββ- he compares links for boxed objects. Since there are two different links, the result is false - and it will be even if both values ββare of type int .
source share