C# difference between == and Equals()

前端 未结 17 1420
走了就别回头了
走了就别回头了 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条回答
  •  梦毁少年i
    2020-11-21 07:59

    When == is used on an expression of type object, it'll resolve to System.Object.ReferenceEquals.

    Equals is just a virtual method and behaves as such, so the overridden version will be used (which, for string type compares the contents).

提交回复
热议问题