CompareInfo Property

CultureInfo.CompareInfo Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets the CompareInfo object that defines how to compare strings for the culture.

Namespace:  System.Globalization
Assembly:  mscorlib (in mscorlib.dll)

Public Overridable ReadOnly Property CompareInfo As CompareInfo

Property Value

Type: System.Globalization.CompareInfo
The object that defines how to compare strings for the culture.

The user might choose to override some of the values associated with the current system culture. For example, the user might choose to display the date in a different format or to use a currency other than the default for the culture. The CultureInfo object that represents the current culture reflects these customizations.

The following example creates es-ES and es-ES_tradnl CultureInfo objects, uses the CompareInfo property to retrieve their CompareInfo objects, and tests the CompareInfo objects for equality. It indicates that the two CompareInfo objects are not equal.

Imports System.Globalization

Public Module Example
   Public Sub Demo(outputBlock As System.Windows.Controls.TextBlock)
      outputBlock.FontFamily = New FontFamily("Courier New")
      ' Instantiate es-ES culture with international and traditional sort orders.
      Dim esIntl As New CultureInfo("es-ES")
      Dim esTrad As New CultureInfo("es-ES_tradnl")

      ' Retrieve respective CompareInfo objects.
      Dim compEsIntl As CompareInfo = esIntl.CompareInfo
      Dim compEsTrad As CompareInfo = esTrad.CompareInfo

      ' Display information on CultureInfo objects.
      outputBlock.Text += String.Format("{0,-15} {1,-15} {2,-17} {3,-18} {4,-18} {5,-20}", _
                          "Name", "ToString", "CompareInfo.Name", "English", _
                          "Native", "Display") + vbCrLf

      outputBlock.Text += String.Format("{0,-15} {1,-15} {2,-17} {3,-18} {4,-18} {5,-30}", _
                          esIntl.Name, esIntl.ToString(), compEsIntl.Name, esIntl.EnglishName, _
                          esIntl.NativeName, esIntl.DisplayName) + vbCrLf 

      outputBlock.Text += String.Format("{0,-15} {1,-15} {2,-17} {3,-18} {4,-18} {5,-30}", _
                          esTrad.Name, esTrad.ToString(), compEsTrad.Name, esTrad.EnglishName, _
                          esTrad.NativeName, esTrad.DisplayName) + vbCrLf +vbCrLf
      ' Test CompreInfo objects for equality.
      outputBlock.Text += String.Format("{0} and {1} are equal: {2}", _
                                        compEsIntl.Name, compEsTrad.Name, _
                                        compEsIntl.Equals(compEsTrad)) + vbCrLf
   End Sub
End Module
' The example displays the following output:
'    Name          ToString        CompareInfo.Name    English          Native            Display
'    es-ES         es-ES           es-ES               Spanish (Spain)  español (España)  Spanish (Spain, International Sort) 
'    es-ES_tradnl  es-ES_tradnl    es-ES_tradnl        Spanish (Spain)  español (España)  Spanish (Spain, Traditional Sort) 
'    es-ES and es-ES_tradnl are equal: False

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2017 Microsoft