Name
Comparer
Synopsis
The Comparer
class is
used to compare two objects
of the same type. The Compare( )
method takes two
objects. If the first object is less than the second, a negative
value is returned. If the first object is greater than the second, a
positive value is returned. If the objects are equal, zero is
returned. The comparisons of strings are case-sensitive. For
case-insensitive string comparisons, use
CaseInsensitiveComparer
. You can obtain a standard
comparer that uses the
System.Globalization.InvariantCulture
rules for
string comparisons by using the
CaseInsensitiveComparer
instance returned from the
static DefaultInvariant
property.
public sealed class Comparer : IComparer { // Public Constructors public Comparer(System.Globalization.CultureInfoculture
); // Public Static Fields public static readonly Comparer Default; // =System.Collections.Comparer public static readonly Comparer DefaultInvariant; // =System.Collections.Comparer // Public Instance Methods public int Compare(objecta
, objectb
); // implements IComparer }
Get C# in a Nutshell, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.