Overloading a comparison operator, how to compare if two variables point to the same object (i.e. not a value)
public static bool operator ==(Landscape a, Landscape b) { return a.Width == b.Width && a.Height == b.Height; } public static bool operator !=(Landscape a, Landscape b) { return !(a.Width == b.Width && a.Height == b.Height); }
Use the static method Object.ReferenceEquals.
Of course, in order for the == and! = Method to retain their full functionality, you must also override Equals and GetHashCode so that they return a consistent set of answers to callers.
Try a.ReferenceEquals(b);
a.ReferenceEquals(b);
, . Object.ReferenceEquals. true, . false
, == Object.Equals, ! =.
, , <, > , < =, > =.
, , , , - CodeRush Refactor, "" ( ), , 25 , . , ==, ! =, .