After overloading the operator==, how to compare if two variables points at the same object?

Posted by Hao on Stack Overflow See other posts from Stack Overflow or by Hao
Published on 2009-03-06T05:35:29Z Indexed on 2010/04/08 2:53 UTC
Read the original article Hit count: 374

Overloading the comparison operator, how to compare if the two variables points to the same object(i.e. not 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);
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about operators