Equals and "==" operator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • #Hai

    Equals and "==" operator

    Hi,
    What is the difference between Object.Equals and "==" operator ?
    When we use CollectionBase. List.Remove(obj ect), which methods is used to
    compare objects ?

    Thanks


  • Anthony Bouch

    #2
    Re: Equals and "==&quo t; operator

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

    " #Hai" <ReplyToNewsgro upOnly@Softhome .net> wrote in message
    news:ekVeJvVPDH A.1908@TK2MSFTN GP11.phx.gbl...[color=blue]
    > Hi,
    > What is the difference between Object.Equals and "==" operator ?
    > When we use CollectionBase. List.Remove(obj ect), which methods is used to
    > compare objects ?
    >
    > Thanks
    >
    >[/color]


    Comment

    • Markus Wildgruber

      #3
      Re: Equals and &quot;==&quo t; operator

      Hi Anthony!

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

      TIA,

      Markus

      "Anthony Bouch" <tony@nospamfor ever.com> schrieb im Newsbeitrag
      news:e2lV4BfPDH A.3192@TK2MSFTN GP10.phx.gbl...[color=blue]
      > For interest, there are also performance differences between instance and
      > static(shared) methods for Equals and the == operator when comparing
      > strings.
      >
      > " #Hai" <ReplyToNewsgro upOnly@Softhome .net> wrote in message
      > news:ekVeJvVPDH A.1908@TK2MSFTN GP11.phx.gbl...[color=green]
      > > Hi,
      > > What is the difference between Object.Equals and "==" operator ?
      > > When we use CollectionBase. List.Remove(obj ect), which methods is used to
      > > compare objects ?
      > >
      > > Thanks
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • 100

        #4
        Re: Equals and &quot;==&quo t; 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.co m> wrote in message
        news:MPG.19677b 53e56b5a99989fb c@news.microsof t.com...[color=blue]
        > [What does this have to do with Windows forms, by the way? Please limit
        > your post to relevant groups - preferrably only one!]
        >
        > #Hai <ReplyToNewsgro upOnly@Softhome .net> wrote:[color=green]
        > > What is the difference between Object.Equals and "==" operator ?[/color]
        >
        > 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
        >[color=green]
        > > When we use CollectionBase. List.Remove(obj ect), which methods is used to
        > > compare objects ?[/color]
        >
        > 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.co m>
        > http://www.pobox.com/~skeet/
        > If replying to the group, please do not mail me too[/color]


        Comment

        • code.book
          New Member
          • Jun 2006
          • 1

          #5
          You can find the answer at

          Comment

          Working...