overload Equals, is this wrong?

Posted by Zka on Stack Overflow See other posts from Stack Overflow or by Zka
Published on 2010-05-15T02:50:40Z Indexed on 2010/05/15 2:54 UTC
Read the original article Hit count: 438

Filed under:
|
|

Reading some piece of code and I keep seeing this :

public override bool Equals (object obj)
{ 
    if (obj == null || this.GetType ().Equals (obj.GetType())) return false; 
    //compare code...
}

Shouldn't it be like this (note the !):

public override bool Equals (object obj)
{ 
    if (obj == null || !this.GetType ().Equals (obj.GetType())) return false; 
    //compare code...
}

Or does the equals perform differently in this case?

© Stack Overflow or respective owner

Related posts about c#

Related posts about equals