System.Collections.CaseInsensitiveComparer Class

Compares two objects for equivalence, ignoring the case of strings.

See Also: CaseInsensitiveComparer Members


public class CaseInsensitiveComparer : IComparer


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.

The objects used as keys by a Hashtable are required to override the object.GetHashCode method (or the IHashCodeProvider interface) and the object.Equals(object) method (or the IComparer interface). The implementation of both methods or interfaces must handle case sensitivity the same way; otherwise, the Hashtable might behave incorrectly. For example, when creating a Hashtable, you must use this class with the CaseInsensitiveHashCodeProvider class or any case-insensitive IHashCodeProvider implementation.

String comparisons might have different results depending on the culture. For more information on culture-specific comparisons, see the System.Globalization namespace and Encoding and Localization.


Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0,,