So as I understand it Equals() determines whether the specified object is equal to the current object.
So if i have this Player class:
public class Player
{
int score;
public object Clone()
{
return this.MemberwiseClone();
}
public void SetScore(int i)
{
this.score = i;
}
public int GetScore()
{
return this.score;
}
}
Ant then I instantiate two Player’s like this:
Player p1 = new Player();
p1.SetScore(7);
Player p2 = (Player)p1.Clone();
Why is it that does Equals() return false when used like this:
Console.WriteLine(p1.Equals(p2)); // prints "False" to console
How are they not equal?
Because unless you override the Equals function, it is comparing the references to see if they are the same object.
See Implementing the Equals Method.
There are cases where you may get some reference, and want to see if it is a certain object. Say: