C# difference between == and Equals()

前端 未结 17 1365
走了就别回头了
走了就别回头了 2020-11-21 06:56

I have a condition in a silverlight application that compares 2 strings, for some reason when I use == it returns false while .Equals()

17条回答
  •  爱一瞬间的悲伤
    2020-11-21 07:44

    Really great answers and examples!

    I would just like to add the fundamental difference between the two,

    Operators such as == are not polymorphic, while Equals is

    With that concept in mind, if you work out any example (by looking at left hand and right hand reference type, and checking/knowing if the type actually has == operator overloaded and Equals being overriden) you are certain to get the right answer.

提交回复
热议问题