There are two binary operators defined on all pairs of values, identity and equality, which return a Boolean result. Both of these operators are mathematical equivalence operators, i.e. they are:
a op a
is true.a op b
is true if and only if b op a
is true. a op b
is true and b op c
is true, then a op c
is trueIn addition, identity always implies equality, but not the reverse, i.e., the equality operator need not be the same as the identity operator as long as two identical values are also equal values.
To understand the difference between these operations, consider three variables whose type is System.String, where the arrow is intended to mean “is a reference to”:
The values of the variables are identical if the locations of the sequences of characters are the same, i.e., there is in fact only one string in memory. The values stored in the variables are equal if the sequences of characters are the same. Thus, the values of variables A and B are identical, the values of variables A and C as well as B and C are not identical, and the values of all three of A, B, and C are equal.
The identity operator is defined by the VOS as follows.
The exact types of the values supply the equality operator. Definitions of equality must obey the following two rules: