This documentation is archived and is not being maintained.

CaseInsensitiveComparer.Compare Method

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.

[Visual Basic]
Public Overridable Function Compare( _
   ByVal a As Object, _
   ByVal b As Object _
) As Integer Implements IComparer.Compare
public virtual int Compare(
 object a,
 object b
public: virtual int Compare(
 Object* a,
 Object* b
public function Compare(
   a : Object,
 b : Object
) : int;


The first object to compare.
The second object to compare.

Return Value

Value Condition
Less than zero a is less than b, with casing ignored.
Zero a equals b, with casing ignored.
Greater than zero a is greater than b, with casing ignored.




Exception Type Condition
ArgumentException Neither a nor b implements the IComparable interface.


a and b are of different types.


If a and b are both strings, this method uses CompareInfo.Compare to compare the strings with the casing ignored; otherwise, it uses the IComparable implementation of either object. That is, if a implements IComparable, then this method returns the result of a. CompareTo (b); otherwise, if b implements IComparable, then it returns the negated result of b. CompareTo (a).

Comparing a null reference (Nothing in Visual Basic) with any type is allowed and does not generate an exception when using IComparable. When sorting, a null reference (Nothing) is considered to be less than any other object.

String comparisons might have different results depending on the culture. For more information on culture-specific comparisons, see the System.Globalization namespace and Developing World-Ready Applications.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

CaseInsensitiveComparer Class | CaseInsensitiveComparer Members | System.Collections Namespace | IComparable | System.Globalization.CompareInfo | Thread.CurrentCulture | System.Globalization.CultureInfo | Performing Culture-Insensitive String Operations in Collections