Never mind. I tried this out as Jeffrey Richter suggested and GetType always
return the same type, no matter you call it in base or derived.

Yong

>  -----Original Message-----
> From:         Yong Xu
> Sent: Friday, May 17, 2002 10:28 AM
> To:   '[EMAIL PROTECTED]'
> Subject:      Implementing Equals
>
> Hi there,
> In Jeffrey Richter's recent book, Applied .NET Framework programming, Page
> 156, he demonstrated how to implement Equals for a reference type whose
> base class overrides Object's Equals. He wrote this,
> // let the base type compare its fields
> if (!base.Equals(obj)) return false;
> ...
> // If the objects are of different types, they can't be equal
> if (this.GetType() != obj.GetType()) return false;
> ...
> However, if the base class implements its Equals in the similar way, since
> GetType is not virtual, then either base's (this.GetType() !=
> obj.GetType()) or the derived class's one must evaluate to false. Hence
> the derived class's Equals will always return false.
> Do I miss anything?
> TIA,
> Yong

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to