Is there a C# equivalent to Python's id()? If not, how can I test if an object has changed? For example, in Python, an immutable object:
>>> s = "abc"
>>> id(s)
11172320
>>> s += "d"
>>> id(s)
18632928
and a mutable one:
>>> a = [1, 2, 3]
>>> id(a)
11259656
>>> a += [4]
>>> id(a)
11259656
Edit - Most of the answers so far are about comparison functions/operators but I'm more interested in the values that are being compared. I wasn't initially clear about that, and I'm accepting Object.ReferenceEquals as the answer.
You can test object identity with Object.ReferenceEquals.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With