StringComparer::Compare Method (String, String)

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

Namespace:  System
Assemblies:   System.Runtime.Extensions (in System.Runtime.Extensions.dll)
  mscorlib (in mscorlib.dll)

public:
virtual int Compare(
	String^ x, 
	String^ y
) abstract

Parameters

x
Type: System::String

A string to compare to y.

y
Type: System::String

A string 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.

Value

Meaning

Less than zero

x precedes y in the sort order.

-or-

x is nullptr and y is not nullptr.

Zero

x is equal to y.

-or-

x and y are both nullptr.

Greater than zero

x follows y in the sort order.

-or-

y is nullptr and x is not nullptr.

Implements

IComparer<T>::Compare(T, T)

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

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft