Compartir a través de


CultureInfo.CompareInfo Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public Overridable ReadOnly Property CompareInfo As CompareInfo
public virtual CompareInfo CompareInfo { get; }

Property Value

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

Remarks

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.

Examples

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
using System;
using System.Globalization;
using System.Windows.Media;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.FontFamily = new FontFamily("Courier New");
      // Instantiate es-ES culture with international and traditional sort orders.
      CultureInfo esIntl = new CultureInfo("es-ES");
      CultureInfo esTrad = new CultureInfo("es-ES_tradnl");

      // Retrieve respective CompareInfo objects.
      CompareInfo compEsIntl  = esIntl.CompareInfo;
      CompareInfo compEsTrad  = esTrad.CompareInfo;

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

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

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

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.