PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Equals and "==" operator

Reply

Equals and "==" operator

 
Thread Tools Rate Thread
Old 28-06-2003, 06:49 AM   #1
#Hai
Guest
 
Posts: n/a
Default Equals and "==" operator


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


  Reply With Quote
Old 29-06-2003, 04:42 AM   #2
Anthony Bouch
Guest
 
Posts: n/a
Default Re: Equals and "==" operator

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

" #Hai" <ReplyToNewsgroupOnly@Softhome.net> wrote in message
news:ekVeJvVPDHA.1908@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
>
>



  Reply With Quote
Old 30-06-2003, 09:45 AM   #3
Markus Wildgruber
Guest
 
Posts: n/a
Default Re: Equals and "==" operator

Hi Anthony!

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

TIA,

Markus

"Anthony Bouch" <tony@nospamforever.com> schrieb im Newsbeitrag
news:e2lV4BfPDHA.3192@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" <ReplyToNewsgroupOnly@Softhome.net> wrote in message
> news:ekVeJvVPDHA.1908@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
> >
> >

>
>



  Reply With Quote
Old 30-06-2003, 08:21 PM   #4
100
Guest
 
Posts: n/a
Default Re: Equals and "==" operator

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" <skeet@pobox.com> wrote in message
news:MPG.19677b53e56b5a99989fbc@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 <ReplyToNewsgroupOnly@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 - <skeet@pobox.com>
> http://www.pobox.com/~skeet/
> If replying to the group, please do not mail me too



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off