views:

43

answers:

1

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?

+2  A: 

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

Mike K