C# StringComparer Compare(String, String)
Description
StringComparer Compare(String, String)
when overridden
in a derived class, compares two strings and returns an indication of their
relative sort order.
Syntax
StringComparer.Compare(String, String)
has the following syntax.
public abstract int Compare(
string x,
string y
)
Parameters
StringComparer.Compare(String, String)
has the following parameters.
x
- A string to compare to y.y
- A string to compare to x.
Returns
StringComparer.Compare(String, String)
method returns A signed integer that indicates the relative values of x and y, as shown in
the following table. Value Meaning Less than zero x is less than y. -or- x is
null. Zero x is equal to y. Greater than zero x is greater than y. -or- y is null.
Example
using System;// w ww . j a va2 s.c om
class Sample
{
public static void Main()
{
StringComparer invCmp = StringComparer.Ordinal;
Console.WriteLine(invCmp.Compare(invCmp,StringComparer.InvariantCulture));
}
}
The code above generates the following result.