I just watched Recommendations on overloading Equals () on msdn (see code below); most of them I understand, but there is one line that I do not get.
if ((System.Object)p == null)
or, in the second redefinition
if ((object)p == null)
Why not just
if (p == null)
What is a throw to buy an object?
public override bool Equals(System.Object obj) { // If parameter is null return false. if (obj == null) { return false; } // If parameter cannot be cast to Point return false. TwoDPoint p = obj as TwoDPoint; if ((System.Object)p == null) { return false; } // Return true if the fields match: return (x == px) && (y == py); } public bool Equals(TwoDPoint p) { // If parameter is null return false: if ((object)p == null) { return false; } // Return true if the fields match: return (x == px) && (y == py); }
source share