Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

StringComparer.Compare Method (Object, Object)

When overridden in a derived class, compares two objects and returns an indication of their relative sort order.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public int Compare(
	Object x,
	Object y


Type: System.Object

An object to compare to y.

Type: System.Object

An object to compare to x.

Return Value

Type: System.Int32
A signed integer that indicates the relative values of x and y, as shown in the following table.



Less than zero

x precedes y in the sort order.


x is null and y is not null.


x is equal to y.


x and y are both null.

Greater than zero

x follows y in the sort order.


y is null and x is not null.


IComparer.Compare(Object, Object)


Neither x nor y is a String object, and neither x nor y implements the IComparable interface.

The StringComparer.Compare(String, String) method is slightly more efficient than the StringComparer.Compare(Object, Object) method because no conversion of the x and y arguments is needed to perform the comparison.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
© 2015 Microsoft