The predefined string equality operators are:
bool operator ==(string x, string y);
bool operator !=(string x, string y);
Two string values are considered equal when one of the following is true:
?Both values are null.
?Both values are non-null references to string instances that have
identical lengths and identical
characters in each character position.
The string equality operators compare string values rather than string
references. When two separate string
instances contain the exact same sequence of characters, the values of the
strings are equal, but the
references are different. [Note: As described in ?4.9.6, the reference
type equality operators can be used to
compare string references instead of string values. end note]
bool operator ==(string x, string y);
bool operator !=(string x, string y);
Two string values are considered equal when one of the following is true:
?Both values are null.
?Both values are non-null references to string instances that have
identical lengths and identical
characters in each character position.
The string equality operators compare string values rather than string
references. When two separate string
instances contain the exact same sequence of characters, the values of the
strings are equal, but the
references are different. [Note: As described in ?4.9.6, the reference
type equality operators can be used to
compare string references instead of string values. end note]
本文详细解释了字符串相等性的定义及其判断标准。当两个字符串都为null或都是指向相同字符序列的非null引用时,认为这两个字符串是相等的。文章强调,在比较时关注的是字符串的内容而非内存地址。
285

被折叠的 条评论
为什么被折叠?



