Comparing strings

suggest change

Although String is a reference type, the == operator compares string values, not references. == and Equals(string) use an ordinal comparison: they do not apply the current culture, and they do not treat composed and decomposed characters as equal.

Culture-sensitive comparison uses String.Compare or String.Equals with a StringComparison such as CurrentCulture. Some sequences then compare as equal even when the code units differ. See the remarks on Strings and CultureInfo.CurrentCulture.

Do not treat equal Length values as proof that two strings are equal, and do not assume unequal lengths mean a culture-sensitive comparison will return non-zero. Different code-unit lengths can still compare equal after normalization.

Use an overload of String.Equals that takes a StringComparison when the default ordinal comparison is not what you want.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents