Alex Rivera | Logout

Why strings does not compare references?

Asked 2011-03-05T13:32:46.253
14

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 operators?

Edit
Report

1 Answer

2

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().
answered 2011-03-05T14:10:45.103

Your Answer