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.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version