> Is there any performance difference between the two equality methods?
Well, they do two very different things. Unless == has been overridden
(which I dislike, apart from a few very special and well-known cases),
== just checks whether the two values on either side are the same - and
for reference types, those values are references. In other words:
object x = (...);
object y = (...);
if (x==y)
checks whether or not x and y are equal references, i.e. whether the
values of x and y are references to the same object.
if (x.Equals(y))
checks whether or not the object x refers to is equal to the object y
refers to, where the class can decide what equality means, so that two
distinct objects can be equal.
> Or any other reason to prefer one over the other?
It depends whether you want to detect reference identity or object
equality.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Doug Holland - 26 Nov 2003 15:33 GMT
Thanks Jon
- Doug
> > Is there any performance difference between the two equality methods?
>
[quoted text clipped - 21 lines]
> It depends whether you want to detect reference identity or object
> equality.
Mark - 26 Nov 2003 19:55 GMT
> It depends whether you want to detect reference identity or object
> equality.
Jon, have you thought about writing up a page for your site that goes into
these == and .Equals() issues? I refer people to your parameters page all
the time, and I think you'd do a great job on this other often-
misunderstood facet of the language.
Mark
Jon Skeet [C# MVP] - 26 Nov 2003 23:10 GMT
> > It depends whether you want to detect reference identity or object
> > equality.
[quoted text clipped - 3 lines]
> the time, and I think you'd do a great job on this other often-
> misunderstood facet of the language.
Good idea. I'll also include it in the FAQ that I've been trying to get
round to compiling...
(Too many pages to write, too little time :)

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Richard A. Lowe - 27 Nov 2003 09:07 GMT
Actually Jon, perhaps you should go with the .NET / Java zeitgeist and start
a blog :) I'd be happy to set you up with a .Text based one (though I
imagine MS gives it's MVPs free ones?)
{*Really* Off topic: As far as exposure, you can't beat it... I only get 30
unique visitors a day, but I'm #6 on Google for "C# .NET blogs" - right
behind Don Box at the moment).
Richard

Signature
Veuillez m'excuser, mon Fran?ais est tr?s pauvre. Cependant, si vous voyez
mauvais C #, c'est mon d?faut!
> >
> > > It depends whether you want to detect reference identity or object
[quoted text clipped - 9 lines]
>
> (Too many pages to write, too little time :)
Jon Skeet [C# MVP] - 27 Nov 2003 09:36 GMT
> Actually Jon, perhaps you should go with the .NET / Java zeitgeist and start
> a blog :) I'd be happy to set you up with a .Text based one (though I
> imagine MS gives it's MVPs free ones?)
Yes, I think so. Must check.
> {*Really* Off topic: As far as exposure, you can't beat it... I only get 30
> unique visitors a day, but I'm #6 on Google for "C# .NET blogs" - right
> behind Don Box at the moment).
I've thought about it - and I'll think about it some more. Thing is,
I'm always "tweaking" my normal pages, and I don't know how easy that
is to do with blogs. Maybe I should investigate them further...

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Richard A. Lowe - 27 Nov 2003 17:37 GMT
Guess it depends on the the software... .in .Text it's easy to edit posts
but I imaging there's some very mature JSP open-source for blogging as well.
I do like that .Text does automatic trackbacks when you link to other blogs
posts and esp. like blogs I can subscribe to via RSS.
R.

Signature
Veuillez m'excuser, mon Fran?ais est tr?s pauvre. Cependant, si vous voyez
mauvais C #, c'est mon d?faut!
> > Actually Jon, perhaps you should go with the .NET / Java zeitgeist and start
> > a blog :) I'd be happy to set you up with a .Text based one (though I
[quoted text clipped - 9 lines]
> I'm always "tweaking" my normal pages, and I don't know how easy that
> is to do with blogs. Maybe I should investigate them further...