System.Globalization.CompareInfo.Compare Method

Compares two strings using the specified System.Globalization.CompareOptions value.

Syntax

public virtual int Compare (string string1, string string2, CompareOptions options)

Parameters

string1
The first string to compare.
string2
The second string to compare.
options
A value that defines how string1 and string2 should be compared. options is either the enumeration value CompareOptions.Ordinal, or a bitwise combination of one or more of the following values: CompareOptions.IgnoreCase, CompareOptions.IgnoreSymbols, CompareOptions.IgnoreNonSpace, CompareOptions.IgnoreWidth, CompareOptions.IgnoreKanaType, and CompareOptions.StringSort.

Returns

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

zero

The two strings are equal.

less than zero

string1 is less than string2.

greater than zero

string1 is greater than 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 call 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