System.Globalization.CompareInfo.Compare Method

Compares a section of one string with a section of another string.

Syntax

public virtual int Compare (string string1, int offset1, int length1, string string2, int offset2, int length2)

Parameters

string1
The first string to compare.
offset1
The zero-based index of the character in string1 at which to start comparing.
length1
The number of consecutive characters in string1 to compare.
string2
The second string to compare.
offset2
The zero-based index of the character in string2 at which to start comparing.
length2
The number of consecutive characters in string2 to compare.

Returns

A 32-bit signed integer indicating the lexical relationship between the two comparands.

zero

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.

Remarks

If a security decision depends on a string comparison or a case change, you should use the CultureInfo.InvariantCulture property to ensure that the behavior is consistent regardless of the culture settings of the operating system.

Note:

When possible, you should use string comparison methods that have a parameter of type System.Globalization.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 CompareOptions.Ordinal or CompareOptions.OrdinalIgnoreCase for security comparisons.

Requirements

Namespace: System.Globalization
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0