System.Collections.Comparer Class

Assembly: Mscorlib.dll
Namespace: System.Collections
Summary
Compares two objects for equivalence, where string comparisons are case-sensitive.
C# Syntax:
[Serializable]
public sealed class Comparer : IComparer
Remarks
This class is the default implementation of the IComparer interface. The CaseInsensitiveComparer class is the implementation of the IComparer interface that performs case-insensitive string comparisons.

Comparison procedures use the Thread.CurrentCulture of the current thread unless otherwise specified. String comparisons might have different results depending on the culture. For more information on culture-specific comparisons, see the System.Globalization namespace and the conceptual topic at MSDN: designingglobalapplications.

See also:
System.Collections Namespace | IComparer | IComparable | CaseInsensitiveComparer | Thread.CurrentCulture | CompareInfo | CultureInfo

System.Collections.Comparer Member List:

Public Fields
Default Gets an instance of Comparer that is always available.
Public Methods
Compare Performs a case-sensitive comparison of two objects of the same type and returns a value indicating whether one is less than, equal to or greater than the other.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Collections.Comparer Member Details

Field: Default
Summary
Gets an instance of Comparer that is always available.
C# Syntax:
public static readonly Comparer Default;
Remarks
An instance of Comparer that is always available.

Return to top


Method: Compare(
   object a,
   object b
)
Summary
Performs a case-sensitive comparison of two objects of the same type and returns a value indicating whether one is less than, equal to or greater than the other.
C# Syntax:
public int Compare(
   object a,
   object b
);
Parameters:

a

The first object to compare.

b

The second object to compare.

Return Value:


Value Condition
Less than zero is less than .
Zero equals .
Greater than zero is greater than .
Exceptions
Exception Type Condition
ArgumentException Neither a nor b implements the IComparable interface.

-or-

a and b are of different types and neither one can handle comparisons with the other.

Implements:
IComparer.Compare
Remarks
If a implements IComparable, then a.CompareTo (b) is returned; otherwise, if b implements IComparable, then b.CompareTo (a) is returned.

Comparing null with any type is allowed and does not generate an exception when using IComparable. When sorting, null is considered to be less than any other object.

Comparison procedures use the Thread.CurrentCulture of the current thread unless otherwise specified. String comparisons might have different results depending on the culture. For more information on culture-specific comparisons, see the System.Globalization namespace and the conceptual topic at MSDN: designingglobalapplications.

See also:
IComparable | Thread.CurrentCulture | CompareInfo | CultureInfo

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~Comparer();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.