Consider this code:
static int x2 = 10;
public static void Main()
{
short y = 10;
Console.WriteLine(y.Equals(x2)); //False
Console.Read();
}
Why y.Equals(x2)
returns false
?
Consider this code:
static int x2 = 10;
public static void Main()
{
short y = 10;
Console.WriteLine(y.Equals(x2)); //False
Console.Read();
}
Why y.Equals(x2)
returns false
?
Int16.Equals
specific docs
Return Value
true if obj is an instance of Int16 and equals the value of this instance; otherwise, false.
This was my original answer, whilst it doesn't apply here, I've left it in as a note for what the .Equals
method is checking for
From the docs,
the Equals(Object) method tests for reference equality
From the documentation, you can read that the specific overload used:
Returns a value indicating whether this instance is equal to a specified object.
And:
true if obj is an instance of System.Int16 and equals the value of this instance; otherwise, false.
A short
is not an int
, so it returns false
.