CultureInfo.CompareInfo Property

May 11, 2014

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

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

public virtual CompareInfo CompareInfo { get; }

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.


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


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft