10.Equals(10f)
result in false
while 10 == 10f
results in true
. Latter is because when comparing an int
with a float
the int
is converted to float
. I just don't understand why int.Equals
obviously does not convert the int
value into float
if the passed object is a float
object.
This in my opinion is a problem with constant matching, when assuming that variable == constant
is identical to variable is constant
. If the variable is of type object
, for example following matching fails:
object value = 10f;
if (value is 10)
{
// This block is not run
}
I would not expect this match to fail. So, why is it that 10.Equals(10f)
result in false
?