Re: about IndexOf
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Thu, 24 Jan 2008 11:06:22 -0800
On Thu, 24 Jan 2008 09:45:12 -0800, Jon Skeet [C# MVP] <skeet@xxxxxxxxx> wrote:
Version B. That way you've only got the actual equality check (for the
equality of "name" fields) in one place.
I agree with that generally (not having copied code). But it begs the question: why the need for the non-virtual Name.Equals(Name) method in the first place? If you've already got the virtual Name.Equals(Object) and it does the right thing, why bother with the other method?
I would think that just having a single method is better in this case, rather than having two, one of which just does the type check before calling the other. The type check isn't that expensive, if I recall correctly, nor is the overhead for the call to the virtual method, and avoiding those performance hits is the only reason I can think of for splitting the behavior up.
Are there places in .NET or C# where having the non-virtual Equals() method is particularly useful?
Pete
.
- Follow-Ups:
- Re: about IndexOf
- From: Jon Skeet [C# MVP]
- Re: about IndexOf
- References:
- about IndexOf
- From: TonyJ
- Re: about IndexOf
- From: Jon Skeet [C# MVP]
- Re: about IndexOf
- From: TonyJ
- Re: about IndexOf
- From: Jon Skeet [C# MVP]
- about IndexOf
- Prev by Date: Re: string == and Equals
- Next by Date: Re: Using VisualBasic 6 Random Access Files in dotnet
- Previous by thread: Re: about IndexOf
- Next by thread: Re: about IndexOf
- Index(es):