Click or drag to resize
StringCompare Method (String, Int32, String, Int32, Int32, StringComparison)
Compares substrings of two specified String objects using the specified rules, and returns an integer that indicates their relative position in the sort order.

Namespace: System
Assembly: mscorlib (in mscorlib.dll) Version: 4.0.0.0
Syntax
C#
public static int Compare(
	string strA,
	int indexA,
	string strB,
	int indexB,
	int length,
	StringComparison comparisonType
)

Parameters

strA
Type: SystemString
The first string to use in the comparison.
indexA
Type: SystemInt32
The position of the substring within strA.
strB
Type: SystemString
The second string to use in the comparison.
indexB
Type: SystemInt32
The position of the substring within strB.
length
Type: SystemInt32
The maximum number of characters in the substrings to compare.
comparisonType
Type: SystemStringComparison
One of the enumeration values that specifies the rules to use in the comparison.

Return Value

Type: Int32
A 32-bit signed integer that indicates the lexical relationship between the two comparands.Value Condition Less than zero The substring in the strA parameter is less than the substring in the strB parameter.Zero The substrings are equal, or the length parameter is zero. Greater than zero The substring in strA is greater than the substring in strB.
Exceptions
ExceptionCondition
ArgumentOutOfRangeExceptionindexA is greater than strA.Length.-or- indexB is greater than strB.Length.-or- indexA, indexB, or length is negative. -or-Either indexA or indexB is null, and length is greater than zero.
ArgumentExceptioncomparisonType is not a StringComparison value.
See Also