Comparer |
IComparer | |
IObject |
Name | Description |
---|---|
Compare | Performs a case-sensitive comparison of two values of the same type and returns a value indicating whether one is less than, equal to, or greater than the other. |
Equals | Returns a boolean indicating if the value and this object instance are the same instance. |
GetHashCode | Returns a pseudo-unique number identifying this instance. |
ToString | Returns a string representation of this object instance. |
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.
The following code example shows how Compare returns different values depending on the culture associated with the Comparer.
Public Sub Main() Const Str1 As String = "Apple" Const Str2 As String = "Æble" Debug.Print CorString.Format("Comparing ""{0}"" and ""{1}"" ...", Str1, Str2) Debug.Print CorString.Format(" Invariant Comparer: {0}", Comparer.DefaultInvariant.Compare(Str1, Str2)) Dim CompUS As Comparer Set CompUS = NewComparer(NewCultureInfo("en-US", False)) Debug.Print CorString.Format("English (United States) Sort: {0}", CompUS.Compare(Str1, Str2)) Dim CompDK As Comparer Set CompDK = NewComparer(NewCultureInfo("da-DK", False)) Debug.Print CorString.Format(" dansk (Danmark) Sort: {0}", CompDK.Compare(Str1, Str2)) End Sub ' This code produces the following output. ' ' Comparing "Apple" and "Æble" ... ' Invariant Comparer: 1 ' English (United States) Sort: 1 ' dansk (Danmark) Sort: -1