CompareInfo.Compare Method (String, Int32, Int32, String, Int32, Int32)
Compares a section of one string with a section of another string.
Assembly: mscorlib (in mscorlib.dll)
abstract Compare : string1:string * offset1:int * length1:int * string2:string * offset2:int * length2:int -> int override Compare : string1:string * offset1:int * length1:int * string2:string * offset2:int * length2:int -> int
The first string to compare.
The zero-based index of the character in string1 at which to start comparing.
The number of consecutive characters in string1 to compare.
The second string to compare.
The zero-based index of the character in string2 at which to start comparing.
The number of consecutive characters in string2 to compare.
Return ValueType: System.Int32
A 32-bit signed integer indicating the lexical relationship between the two comparands.
The two strings are equal.
less than zero
The specified section of string1 is less than the specified section of string2.
greater than zero
The specified section of string1 is greater than the specified section of string2.
offset1 or length1 or offset2 or length2 is less than zero.
offset1 is greater than or equal to the number of characters in string1.
offset2 is greater than or equal to the number of characters in string2.
length1 is greater than the number of characters from offset1 to the end of string1.
length2 is greater than the number of characters from offset2 to the end of string2.
If a security decision depends on a string comparison or a case change, you should use the InvariantCulture property to ensure that the behavior is consistent regardless of the culture settings of the operating system.
When possible, you should use string comparison methods that have a parameter of type CompareOptions to specify the kind of comparison expected. As a general rule, use linguistic options (using the current culture) for comparing strings displayed in the user interface and specify Ordinal or OrdinalIgnoreCase for security comparisons.
Notes to Callers:
Character sets include ignorable characters. The Compare(String, Int32, Int32, String, Int32, Int32, CompareOptions) method and supply a value of CompareOptions.Ordinal or CompareOptions.OrdinalIgnoreCase for the options parameter.method does not consider these characters when it performs a linguistic or culture-sensitive comparison. To recognize ignorable characters in your comparison, call the
The following example compares portions of two strings using the different CompareInfo objects:
Available since 8
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1