开发者

overload Equals, is this wrong?

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?


That looks like a bug. Returning false when the types are the same is certainly not the intended behaviour.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜