We know all types inherit Equals from their base class, which is Object.
Per Microsoft docs:
Equals returns true only if the items being compared refer to the same item in memory.
So we use Equals() to compare object references, not the state of the object.
Typically, this method is overridden to return true only if the objects being compared have the same internal state values.
My Question: Can two objects point to the same item in memory but have different states? If not why override Equals?
Thanks for answers that made this clear. For future readers here is an example of why we override:
Employee A=New Employee();
Employee B=New Employee();
in this case, A and B always point to different memory so Equals is always false.
However if:
A.SSN=B.SSN;
A.LiceneNumber=B.LiceneNumber;
These two Employees are the same person, in this case, we need to check state and therefore override Equals.
So in my case, the point of the matter is: it is possible that two different objects are stored in two different locations but still refer to same entity (in my case Employee).