CultureInfo.CompareInfo 属性

获取为区域性定义如何比较字符串的 CompareInfo

**命名空间:**System.Globalization
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public Overridable ReadOnly Property CompareInfo As CompareInfo
用法
Dim instance As CultureInfo
Dim value As CompareInfo

value = instance.CompareInfo
public virtual CompareInfo CompareInfo { get; }
public:
virtual property CompareInfo^ CompareInfo {
    CompareInfo^ get ();
}
/** @property */
public CompareInfo get_CompareInfo ()
public function get CompareInfo () : CompareInfo

属性值

为区域性定义如何比较字符串的 CompareInfo

备注

用户可以通过“控制面板”中的“区域和语言选项”(或“区域选项”或“区域设置”)选择重写某些与 Windows 的当前区域性关联的值。例如,用户可能选择以另一种格式显示日期,或选择使用区域性默认设置以外的货币。

如果 UseUserOverridetrue 并且指定的区域性与当前 Windows 的区域性匹配,则 CultureInfo 使用那些重写,包括以下属性的用户设置:由 DateTimeFormat 属性返回的 DateTimeFormatInfo 实例的属性以及由 NumberFormat 属性返回的 NumberFormatInfo 实例的属性。如果用户设置与 CultureInfo 的关联区域性不兼容(例如选定的日历不属于 OptionalCalendars 其中之一),则方法结果和属性值是未定义的。

示例

下面的代码示例显示如何按国际排序创建一个用于“西班牙语-西班牙”的 CultureInfo,并按传统排序创建另一个 CultureInfo

Imports System
Imports System.Collections
Imports System.Globalization

Public Class SamplesCultureInfo

   Public Shared Sub Main()

      ' Creates and initializes the CultureInfo which uses the international sort.
      Dim myCIintl As New CultureInfo("es-ES", False)

      ' Creates and initializes the CultureInfo which uses the traditional sort.
      Dim myCItrad As New CultureInfo(&H40A, False)

      ' Displays the properties of each culture.
      Console.WriteLine("{0,-33}{1,-25}{2,-25}", "PROPERTY", "INTERNATIONAL", "TRADITIONAL")
      Console.WriteLine("{0,-33}{1,-25}{2,-25}", "CompareInfo", myCIintl.CompareInfo, myCItrad.CompareInfo)
      Console.WriteLine("{0,-33}{1,-25}{2,-25}", "DisplayName", myCIintl.DisplayName, myCItrad.DisplayName)
      Console.WriteLine("{0,-33}{1,-25}{2,-25}", "EnglishName", myCIintl.EnglishName, myCItrad.EnglishName)
      Console.WriteLine("{0,-33}{1,-25}{2,-25}", "IsNeutralCulture", myCIintl.IsNeutralCulture, myCItrad.IsNeutralCulture)
      Console.WriteLine("{0,-33}{1,-25}{2,-25}", "IsReadOnly", myCIintl.IsReadOnly, myCItrad.IsReadOnly)
      Console.WriteLine("{0,-33}{1,-25}{2,-25}", "LCID", myCIintl.LCID, myCItrad.LCID)
      Console.WriteLine("{0,-33}{1,-25}{2,-25}", "Name", myCIintl.Name, myCItrad.Name)
      Console.WriteLine("{0,-33}{1,-25}{2,-25}", "NativeName", myCIintl.NativeName, myCItrad.NativeName)
      Console.WriteLine("{0,-33}{1,-25}{2,-25}", "Parent", myCIintl.Parent, myCItrad.Parent)
      Console.WriteLine("{0,-33}{1,-25}{2,-25}", "TextInfo", myCIintl.TextInfo, myCItrad.TextInfo)
      Console.WriteLine("{0,-33}{1,-25}{2,-25}", "ThreeLetterISOLanguageName", myCIintl.ThreeLetterISOLanguageName, myCItrad.ThreeLetterISOLanguageName)
      Console.WriteLine("{0,-33}{1,-25}{2,-25}", "ThreeLetterWindowsLanguageName", myCIintl.ThreeLetterWindowsLanguageName, myCItrad.ThreeLetterWindowsLanguageName)
      Console.WriteLine("{0,-33}{1,-25}{2,-25}", "TwoLetterISOLanguageName", myCIintl.TwoLetterISOLanguageName, myCItrad.TwoLetterISOLanguageName)
      Console.WriteLine()

      ' Compare two strings using myCIintl.
      Console.WriteLine("Comparing ""llegar"" and ""lugar""")
      Console.WriteLine("   With myCIintl.CompareInfo.Compare: {0}", myCIintl.CompareInfo.Compare("llegar", "lugar"))
      Console.WriteLine("   With myCItrad.CompareInfo.Compare: {0}", myCItrad.CompareInfo.Compare("llegar", "lugar"))

   End Sub 'Main 

End Class 'SamplesCultureInfo


'This code produces the following output.
'
'PROPERTY                         INTERNATIONAL            TRADITIONAL
'CompareInfo                      CompareInfo - 3082       CompareInfo - 1034
'DisplayName                      Spanish (Spain)          Spanish (Spain)
'EnglishName                      Spanish (Spain)          Spanish (Spain)
'IsNeutralCulture                 False                    False
'IsReadOnly                       False                    False
'LCID                             3082                     1034
'Name                             es-ES                    es-ES
'NativeName                       español (España)         español (España)
'Parent                           es                       es
'TextInfo                         TextInfo - 3082          TextInfo - 1034
'ThreeLetterISOLanguageName       spa                      spa
'ThreeLetterWindowsLanguageName   ESN                      ESN
'TwoLetterISOLanguageName         es                       es
'
'Comparing "llegar" and "lugar"
'   With myCIintl.CompareInfo.Compare: -1
'   With myCItrad.CompareInfo.Compare: 1
using System;
using System.Collections;
using System.Globalization;


public class SamplesCultureInfo  {

   public static void Main()  {

      // Creates and initializes the CultureInfo which uses the international sort.
      CultureInfo myCIintl = new CultureInfo( "es-ES", false );
      
      // Creates and initializes the CultureInfo which uses the traditional sort.
      CultureInfo myCItrad = new CultureInfo( 0x040A, false );

      // Displays the properties of each culture.
      Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "PROPERTY", "INTERNATIONAL", "TRADITIONAL" );
      Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "CompareInfo", myCIintl.CompareInfo, myCItrad.CompareInfo );
      Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "DisplayName", myCIintl.DisplayName, myCItrad.DisplayName );
      Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "EnglishName", myCIintl.EnglishName, myCItrad.EnglishName );
      Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "IsNeutralCulture", myCIintl.IsNeutralCulture, myCItrad.IsNeutralCulture );
      Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "IsReadOnly", myCIintl.IsReadOnly, myCItrad.IsReadOnly );
      Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "LCID", myCIintl.LCID, myCItrad.LCID );
      Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "Name", myCIintl.Name, myCItrad.Name );
      Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "NativeName", myCIintl.NativeName, myCItrad.NativeName );
      Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "Parent", myCIintl.Parent, myCItrad.Parent );
      Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "TextInfo", myCIintl.TextInfo, myCItrad.TextInfo );
      Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "ThreeLetterISOLanguageName", myCIintl.ThreeLetterISOLanguageName, myCItrad.ThreeLetterISOLanguageName );
      Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "ThreeLetterWindowsLanguageName", myCIintl.ThreeLetterWindowsLanguageName, myCItrad.ThreeLetterWindowsLanguageName );
      Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "TwoLetterISOLanguageName", myCIintl.TwoLetterISOLanguageName, myCItrad.TwoLetterISOLanguageName );
      Console.WriteLine();

      // Compare two strings using myCIintl.
      Console.WriteLine( "Comparing \"llegar\" and \"lugar\"" );
      Console.WriteLine( "   With myCIintl.CompareInfo.Compare: {0}", myCIintl.CompareInfo.Compare( "llegar", "lugar" ) );
      Console.WriteLine( "   With myCItrad.CompareInfo.Compare: {0}", myCItrad.CompareInfo.Compare( "llegar", "lugar" ) );

   }

}

/*
This code produces the following output.

PROPERTY                         INTERNATIONAL            TRADITIONAL
CompareInfo                      CompareInfo - 3082       CompareInfo - 1034
DisplayName                      Spanish (Spain)          Spanish (Spain)
EnglishName                      Spanish (Spain)          Spanish (Spain)
IsNeutralCulture                 False                    False
IsReadOnly                       False                    False
LCID                             3082                     1034
Name                             es-ES                    es-ES
NativeName                       español (España)         español (España)
Parent                           es                       es
TextInfo                         TextInfo - 3082          TextInfo - 1034
ThreeLetterISOLanguageName       spa                      spa
ThreeLetterWindowsLanguageName   ESN                      ESN
TwoLetterISOLanguageName         es                       es

Comparing "llegar" and "lugar"
   With myCIintl.CompareInfo.Compare: -1
   With myCItrad.CompareInfo.Compare: 1

*/
using namespace System;
using namespace System::Collections;
using namespace System::Globalization;
int main()
{
   
   // Creates and initializes the CultureInfo which uses the international sort.
   CultureInfo^ myCIintl = gcnew CultureInfo( "es-ES",false );
   
   // Creates and initializes the CultureInfo which uses the traditional sort.
   CultureInfo^ myCItrad = gcnew CultureInfo( 0x040A,false );
   
   // Displays the properties of each culture.
   Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "PROPERTY", "INTERNATIONAL", "TRADITIONAL" );
   Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "CompareInfo", myCIintl->CompareInfo, myCItrad->CompareInfo );
   Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "DisplayName", myCIintl->DisplayName, myCItrad->DisplayName );
   Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "EnglishName", myCIintl->EnglishName, myCItrad->EnglishName );
   Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "IsNeutralCulture", myCIintl->IsNeutralCulture, myCItrad->IsNeutralCulture );
   Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "IsReadOnly", myCIintl->IsReadOnly, myCItrad->IsReadOnly );
   Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "LCID", myCIintl->LCID, myCItrad->LCID );
   Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "Name", myCIintl->Name, myCItrad->Name );
   Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "NativeName", myCIintl->NativeName, myCItrad->NativeName );
   Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "Parent", myCIintl->Parent, myCItrad->Parent );
   Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "TextInfo", myCIintl->TextInfo, myCItrad->TextInfo );
   Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "ThreeLetterISOLanguageName", myCIintl->ThreeLetterISOLanguageName, myCItrad->ThreeLetterISOLanguageName );
   Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "ThreeLetterWindowsLanguageName", myCIintl->ThreeLetterWindowsLanguageName, myCItrad->ThreeLetterWindowsLanguageName );
   Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "TwoLetterISOLanguageName", myCIintl->TwoLetterISOLanguageName, myCItrad->TwoLetterISOLanguageName );
   Console::WriteLine();
   
   // Compare two strings using myCIintl -> 
   Console::WriteLine( "Comparing \"llegar\" and \"lugar\"" );
   Console::WriteLine( "   With myCIintl -> CompareInfo -> Compare: {0}", myCIintl->CompareInfo->Compare( "llegar", "lugar" ) );
   Console::WriteLine( "   With myCItrad -> CompareInfo -> Compare: {0}", myCItrad->CompareInfo->Compare( "llegar", "lugar" ) );
}

/*
This code produces the following output.

PROPERTY                         INTERNATIONAL            TRADITIONAL              
CompareInfo                      CompareInfo - 3082       CompareInfo - 1034       
DisplayName                      Spanish (Spain)          Spanish (Spain)          
EnglishName                      Spanish (Spain)          Spanish (Spain)          
IsNeutralCulture                 False                    False                    
IsReadOnly                       False                    False                    
LCID                             3082                     1034                     
Name                             es-ES                    es-ES                    
NativeName                       español (España)         español (España)         
Parent                           es                       es                       
TextInfo                         TextInfo - 3082          TextInfo - 1034          
ThreeLetterISOLanguageName       spa                      spa                      
ThreeLetterWindowsLanguageName   ESN                      ESN                      
TwoLetterISOLanguageName         es                       es                       

Comparing "llegar" and "lugar"
   With myCIintl -> CompareInfo -> Compare: -1
   With myCItrad -> CompareInfo -> Compare: 1

*/
import System.* ;
import System.Collections.* ;
import System.Globalization.* ;

public class SamplesCultureInfo
{  
     public static void main(String[] args)
    {
        // Creates and initializes the CultureInfo which uses the 
        // international sort.
        CultureInfo myCIintl =  new CultureInfo("es-ES", false);

        // Creates and initializes the CultureInfo which uses the 
        // traditional sort.
        CultureInfo myCItrad =  new CultureInfo(0x40A, false);

        // Displays the properties of each culture.
        Console.WriteLine("{0,-33}{1,-25}{2,-25}", "PROPERTY", 
            "INTERNATIONAL", "TRADITIONAL");
        Console.WriteLine("{0,-33}{1,-25}{2,-25}", "CompareInfo", 
            myCIintl.get_CompareInfo(), myCItrad.get_CompareInfo());
        Console.WriteLine("{0,-33}{1,-25}{2,-25}", "DisplayName", 
            myCIintl.get_DisplayName(), myCItrad.get_DisplayName());
        Console.WriteLine("{0,-33}{1,-25}{2,-25}", "EnglishName", 
            myCIintl.get_EnglishName(), myCItrad.get_EnglishName());
        Console.WriteLine("{0,-33}{1,-25}{2,-25}", "IsNeutralCulture", 
            System.Convert.ToString(myCIintl.get_IsNeutralCulture()), 
            System.Convert.ToString(myCItrad.get_IsNeutralCulture()));
        Console.WriteLine("{0,-33}{1,-25}{2,-25}", "IsReadOnly", 
            System.Convert.ToString(myCIintl.get_IsReadOnly()), 
            System.Convert.ToString(myCItrad.get_IsReadOnly()));
        Console.WriteLine("{0,-33}{1,-25}{2,-25}", "LCID", 
            System.Convert.ToString(myCIintl.get_LCID()), 
            System.Convert.ToString(myCItrad.get_LCID()));
        Console.WriteLine("{0,-33}{1,-25}{2,-25}", "Name", 
            myCIintl.get_Name(), myCItrad.get_Name());
        Console.WriteLine("{0,-33}{1,-25}{2,-25}", "NativeName", 
            myCIintl.get_NativeName(), myCItrad.get_NativeName());
        Console.WriteLine("{0,-33}{1,-25}{2,-25}", "Parent", 
            myCIintl.get_Parent(), myCItrad.get_Parent());
        Console.WriteLine("{0,-33}{1,-25}{2,-25}", "TextInfo",
            myCIintl.get_TextInfo(), myCItrad.get_TextInfo());
        Console.WriteLine("{0,-33}{1,-25}{2,-25}", 
            "ThreeLetterISOLanguageName", 
            myCIintl.get_ThreeLetterISOLanguageName(), 
            myCItrad.get_ThreeLetterISOLanguageName());
        Console.WriteLine("{0,-33}{1,-25}{2,-25}", 
            "ThreeLetterWindowsLanguageName", 
            myCIintl.get_ThreeLetterWindowsLanguageName(),
            myCItrad.get_ThreeLetterWindowsLanguageName());
        Console.WriteLine("{0,-33}{1,-25}{2,-25}", "TwoLetterISOLanguageName",
            myCIintl.get_TwoLetterISOLanguageName(), 
            myCItrad.get_TwoLetterISOLanguageName());
        Console.WriteLine();

        // Compare two strings using myCIintl.
        Console.WriteLine("Comparing \"llegar\" and \"lugar\"");
        Console.WriteLine("   With myCIintl.CompareInfo.Compare: {0}",
            System.Convert.ToString ( myCIintl.get_CompareInfo().Compare(
            "llegar", "lugar")));
        Console.WriteLine("   With myCItrad.CompareInfo.Compare: {0}", 
            System.Convert.ToString ( myCItrad.get_CompareInfo().Compare(
            "llegar", "lugar")));
    } //main 
} //SamplesCultureInfo

/*
This code produces the following output.

PROPERTY                         INTERNATIONAL            TRADITIONAL
CompareInfo                      CompareInfo - 3082       CompareInfo - 1034
DisplayName                      Spanish (Spain)          Spanish (Spain)
EnglishName                      Spanish (Spain)          Spanish (Spain)
IsNeutralCulture                 False                    False
IsReadOnly                       False                    False
LCID                             3082                     1034
Name                             es-ES                    es-ES
NativeName                       espaol (Espaa)         espaol (Espaa)
Parent                           es                       es
TextInfo                         TextInfo - 3082          TextInfo - 1034
ThreeLetterISOLanguageName       spa                      spa
ThreeLetterWindowsLanguageName   ESN                      ESN
TwoLetterISOLanguageName         es                       es

Comparing "llegar" and "lugar"
   With myCIintl.CompareInfo.Compare: -1
   With myCItrad.CompareInfo.Compare: 1
*/

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

CultureInfo 类
CultureInfo 成员
System.Globalization 命名空间
CompareInfo 类