Why strings does not compare references?

后端 未结 5 1086
耶瑟儿~
耶瑟儿~ 2021-01-11 23:54

I know it is special case but why == between strings returns if their value equals and not when their reference equals. Does it have something to do with overlloading operat

5条回答
  •  花落未央
    2021-01-12 00:26

    The equality operators (== and !=) are defined to compare the values of string objects, not references.

    There was not any situation in which I had to compare the references but if you want to do so then you can use:

    object.ReferenceEquals().
    

提交回复
热议问题