By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,666 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,666 IT Pros & Developers. It's quick & easy.

Equals and "==" operator

P: n/a
Hi,
What is the difference between Object.Equals and "==" operator ?
When we use CollectionBase.List.Remove(object), which methods is used to
compare objects ?

Thanks
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
For interest, there are also performance differences between instance and
static(shared) methods for Equals and the == operator when comparing
strings.

" #Hai" <Re******************@Softhome.net> wrote in message
news:ek**************@TK2MSFTNGP11.phx.gbl...
Hi,
What is the difference between Object.Equals and "==" operator ?
When we use CollectionBase.List.Remove(object), which methods is used to
compare objects ?

Thanks

Nov 13 '05 #2

P: n/a
Hi Anthony!

Can you tell me more about the performance differences. Which way is
fastest?

TIA,

Markus

"Anthony Bouch" <to**@nospamforever.com> schrieb im Newsbeitrag
news:e2**************@TK2MSFTNGP10.phx.gbl...
For interest, there are also performance differences between instance and
static(shared) methods for Equals and the == operator when comparing
strings.

" #Hai" <Re******************@Softhome.net> wrote in message
news:ek**************@TK2MSFTNGP11.phx.gbl...
Hi,
What is the difference between Object.Equals and "==" operator ?
When we use CollectionBase.List.Remove(object), which methods is used to
compare objects ?

Thanks


Nov 13 '05 #3

P: n/a
100
Furthermore, not all languages support operator overloading. So, if one
wants to write language independent code she/he should not rely on operator
overloading. For c# convenince the operators might be overloaded and the
virtual method might be used internally.

B/rgds
100

"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
[What does this have to do with Windows forms, by the way? Please limit
your post to relevant groups - preferrably only one!]

#Hai <Re******************@Softhome.net> wrote:
What is the difference between Object.Equals and "==" operator ?


Operators are not applied polymorphically, methods are. For instance:

string x = "hello";
string y = new string (x.ToCharArray());

object a=x;
object b=y;

x==y; // True, because String== is applied
a==b; // False, because Object== is applied, which asserts reference
// identity

x.Equals(y); // True, because String.Equals override Object.Equals
a.Equals(b); // True, because methods are invoked polymorphically
When we use CollectionBase.List.Remove(object), which methods is used to
compare objects ?


Almost certainly Equals - it's the only way that makes sense, really,
given that CollectionBase only knows about Objects, so to remove
entries you'd have to have the exact reference if it used ==.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Nov 13 '05 #4

P: 1
You can find the answer at
http://groups.google.co.in/group/a-c-net
Jun 29 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.