For my own implementation of an Equals() method, I want to check a bunch of internal fields. I do it like this:
...
_myNullableInt == obj._myNullableInt &&
_myString == obj._myString &&
...
I would assume, that this compares the values, including null, for equality not the object address (as a reference euqality compare operation would) because:
It is said so for "predefined value types" in this MSDN doc here.
I assume Nullable<int>
is such a "predefined value type" because of it is in the System
Namespace according to this MSDN doc.
Am I right to assume that the VALUES are compared here?
Note: Unit tests showed "Yes", but I wanted to be reassured by others with this question, just in case I missed something.
Best Answer
In C#, there's a concept called "Lifted Operators", described in section 7.3.7 of the language specification (Version 5 download):
And specifically:
So, since there's an
==
operator defined betweenint
s, there's also one defined forint?
s