System.Collections.Comparer Class

public sealed class Comparer : IComparer

Base Types

Object
  Comparer

This type implements IComparer.

Assembly

mscorlib

Library

BCL

Summary

Provides the default implementation of the IComparer interface.

See Also

System.Collections Namespace

Members

Comparer Methods

Comparer.Compare Method

Comparer Fields

Comparer.Default Field


Comparer.Compare Method

public int Compare(object a, object b);

Summary

Returns the sort order of two Object instances.

Parameters

a
The first Object to compare.
b
The second Object to compare.

Return Value

A Int32 containing a value that reflects the sort order of a as compared to b. The following table defines the conditions under which the returned value is a negative number, zero, or a positive number.

ValueCondition
Any negative numbera < b.
Zeroa == b.
Any positive numbera > b.
[Note: A null reference is considered to compare less than any other non-null object, and equal to any other null reference, independent of the underlying Type of either object.]

Exceptions

Exception TypeCondition
ArgumentExceptionBoth a and b are not null and do not implement the IComparable interface.

-or-

Both a and b are not null and are not assignment-compatible types.

Description

The behavior of this method is as follows:

See Also

System.Collections.Comparer Class, System.Collections Namespace

Comparer.Default Field

public static readonly Comparer Default;

Summary

Returns a new Comparer instance containing the default implementation of the IComparer interface.

Description

This field is read-only.

See Also

System.Collections.Comparer Class, System.Collections Namespace