C# StringComparer Compare(Object, Object)
Description
StringComparer Compare(Object, Object)
when overridden
in a derived class, compares two objects and returns an indication of their
relative sort order.
Syntax
StringComparer.Compare(Object, Object)
has the following syntax.
public int Compare(
Object x,
Object y
)
Parameters
StringComparer.Compare(Object, Object)
has the following parameters.
x
- An object to compare to y.y
- An object to compare to x.
Returns
StringComparer.Compare(Object, Object)
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 w w . j a va 2 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.