开发者

overload Equals, is this wrong?

开发者 https://www.devze.com 2022-12-30 03:50 出处:网络
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;

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

精彩评论

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