System.Collections.CaseInsensitiveComparer Class

Assembly: Mscorlib.dll
Namespace: System.Collections
Summary
Compares two objects for equivalence, ignoring the case of strings.
C# Syntax:
[Serializable]
public class CaseInsensitiveComparer : IComparer
Remarks
CaseInsensitiveComparer implements the IComparer interface supporting case-insensitive comparisons on strings, just as CaseInsensitiveHashCodeProvider implements the IHashCodeProvider interface supporting case-insensitive comparisons on strings.

The Comparer class is the default implementation of the IComparer interface and performs case-sensitive 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 | Comparer | Thread.CurrentCulture | CompareInfo | CultureInfo

System.Collections.CaseInsensitiveComparer Member List:

Public Constructors
ctor #1 Overloaded:
.ctor()

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new instance of the CaseInsensitiveComparer class using the Thread.CurrentCulture of the current thread.
ctor #2 Overloaded:
.ctor(CultureInfo culture)

Initializes a new instance of the CaseInsensitiveComparer class using the specified CultureInfo.
Public Properties
Default Read-only

Gets an instance of CaseInsensitiveComparer that is always available.
Public Methods
Compare Performs a case-insensitive 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.CaseInsensitiveComparer Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the CaseInsensitiveComparer class using the Thread.CurrentCulture of the current thread.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public CaseInsensitiveComparer();
Remarks
Comparison procedures use the Thread.CurrentCulture of the current thread to determine the sort order. 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:
Thread.CurrentCulture | CompareInfo | CultureInfo

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of the CaseInsensitiveComparer class using the specified CultureInfo.
C# Syntax:
public CaseInsensitiveComparer(
   CultureInfo culture
);
Parameters:

culture

The CultureInfo to use for the new CaseInsensitiveComparer.

Exceptions
Exception Type Condition
ArgumentNullException culture is null.
Remarks
Comparison procedures use the specified CultureInfo to determine the sort order. 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:
Thread.CurrentCulture | CompareInfo | CultureInfo

Return to top


Property: Default (read-only)
Summary
Gets an instance of CaseInsensitiveComparer that is always available.
C# Syntax:
public static CaseInsensitiveComparer Default {get;}

Return to top


Method: Compare(
   object a,
   object b
)
Summary
Performs a case-insensitive 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 , with casing ignored.
Zero equals , with casing ignored.
Greater than zero is greater than , with casing ignored.
Exceptions
Exception Type Condition
ArgumentException Neither a nor b implements the IComparable interface.

-or-

a and b are of different types.

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:
~CaseInsensitiveComparer();

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.