J
John Mark Howell
Why is Int32.Equals(Int16) always false?
The following code:
<code>
Int32 a = 123;
Int16 b = 123;
if (a.Equals(b))
Console.WriteLine("a.Equals(b) is true");
else
Console.WriteLine("a.Equals(b) is false");
if (a == b)
Console.WriteLine("a == b is true");
else
Console.WriteLine("a == b is false");
</code>
will generate the following output:
a.Equals(b) is false
a == b is true
Why?
The following code:
<code>
Int32 a = 123;
Int16 b = 123;
if (a.Equals(b))
Console.WriteLine("a.Equals(b) is true");
else
Console.WriteLine("a.Equals(b) is false");
if (a == b)
Console.WriteLine("a == b is true");
else
Console.WriteLine("a == b is false");
</code>
will generate the following output:
a.Equals(b) is false
a == b is true
Why?