C# difference between == and Equals()

前端 未结 17 1423
走了就别回头了
走了就别回头了 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:37

    The only difference between Equal and == is on object type comparison. in other cases, such as reference types and value types, they are almost the same(either both are bit-wise equality or both are reference equality).

    object: Equals: bit-wise equality ==: reference equality

    string: (equals and == are the same for string, but if one of string changed to object, then comparison result will be different) Equals: bit-wise equality == : bit-wise equality

    See here for more explanation.

提交回复
热议问题