
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
50
|
Chapter 2: Strings and Characters
The caseSensitiveResult value is -1 (indicating that lowerCase is “less than”
upperCase) and the caseInsensitiveResult is zero (indicating that lowerCase “equals”
upperCase).
Discussion
Using the static string.Compare method allows you the freedom to choose whether to
take into account the case of the strings when comparing them. This method returns
an integer indicating the lexical relationship between the two strings. A zero means
that the two strings are equal, a negative number means that the first string is less
than the second string, and a positive number indicates that the first string is greater
than the second string.
By setting the last parameter of this method (the
comparisonType parameter) to either
StringComparison.CurrentCultureIgnoreCase or StringComparison.CurrentCulture,
you can determine whether the
Compare method takes into account the case of both
strings when comparing. Setting this parameter to
StringComparison.CurrentCulture
forces a case-sensitive comparison; setting it to StringComparison.CurrentCulture-
IgnoreCase
forces a case-insensitive comparison. In the case of the overloaded ver-
sion of the method with no
comparisonType parameter, comparisons are always case-
sensitive.
See Also
See the “String.Compare Method” topic in the ...