RegionInfo 类

定义

包含有关国家/地区的信息。Contains information about the country/region.

public ref class RegionInfo
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class RegionInfo
type RegionInfo = class
Public Class RegionInfo
继承
RegionInfo
属性

示例

下面的示例演示了RegionInfo类的多个成员。The following example demonstrates several members of the RegionInfo class.

using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Displays the property values of the RegionInfo for "US".
   RegionInfo^ myRI1 = gcnew RegionInfo( "US" );
   Console::WriteLine( "   Name:                         {0}", myRI1->Name );
   Console::WriteLine( "   DisplayName:                  {0}", myRI1->DisplayName );
   Console::WriteLine( "   EnglishName:                  {0}", myRI1->EnglishName );
   Console::WriteLine( "   IsMetric:                     {0}", myRI1->IsMetric );
   Console::WriteLine( "   ThreeLetterISORegionName:     {0}", myRI1->ThreeLetterISORegionName );
   Console::WriteLine( "   ThreeLetterWindowsRegionName: {0}", myRI1->ThreeLetterWindowsRegionName );
   Console::WriteLine( "   TwoLetterISORegionName:       {0}", myRI1->TwoLetterISORegionName );
   Console::WriteLine( "   CurrencySymbol:               {0}", myRI1->CurrencySymbol );
   Console::WriteLine( "   ISOCurrencySymbol:            {0}", myRI1->ISOCurrencySymbol );
   Console::WriteLine();
   
   // Compares the RegionInfo above with another RegionInfo created using CultureInfo.
   RegionInfo^ myRI2 = gcnew RegionInfo( (gcnew CultureInfo( "en-US",false ))->LCID );
   if ( myRI1->Equals( myRI2 ) )
      Console::WriteLine( "The two RegionInfo instances are equal." );
   else
      Console::WriteLine( "The two RegionInfo instances are NOT equal." );
}

/*
This code produces the following output.

   Name:                         US
   DisplayName:                  United States
   EnglishName:                  United States
   IsMetric:                     False
   ThreeLetterISORegionName:     USA
   ThreeLetterWindowsRegionName: USA
   TwoLetterISORegionName:       US
   CurrencySymbol:               $
   ISOCurrencySymbol:            USD

The two RegionInfo instances are equal.

*/
using System;
using System.Globalization;

public class SamplesRegionInfo  {

   public static void Main()  {

      // Displays the property values of the RegionInfo for "US".
      RegionInfo myRI1 = new RegionInfo( "US" );
      Console.WriteLine( "   Name:                         {0}", myRI1.Name );
      Console.WriteLine( "   DisplayName:                  {0}", myRI1.DisplayName );
      Console.WriteLine( "   EnglishName:                  {0}", myRI1.EnglishName );
      Console.WriteLine( "   IsMetric:                     {0}", myRI1.IsMetric );
      Console.WriteLine( "   ThreeLetterISORegionName:     {0}", myRI1.ThreeLetterISORegionName );
      Console.WriteLine( "   ThreeLetterWindowsRegionName: {0}", myRI1.ThreeLetterWindowsRegionName );
      Console.WriteLine( "   TwoLetterISORegionName:       {0}", myRI1.TwoLetterISORegionName );
      Console.WriteLine( "   CurrencySymbol:               {0}", myRI1.CurrencySymbol );
      Console.WriteLine( "   ISOCurrencySymbol:            {0}", myRI1.ISOCurrencySymbol );
      Console.WriteLine();

      // Compares the RegionInfo above with another RegionInfo created using CultureInfo.
      RegionInfo myRI2 = new RegionInfo( new CultureInfo("en-US",false).LCID );
      if ( myRI1.Equals( myRI2 ) )
         Console.WriteLine( "The two RegionInfo instances are equal." );
      else
         Console.WriteLine( "The two RegionInfo instances are NOT equal." );

   }

}

/*
This code produces the following output.

   Name:                         US
   DisplayName:                  United States
   EnglishName:                  United States
   IsMetric:                     False
   ThreeLetterISORegionName:     USA
   ThreeLetterWindowsRegionName: USA
   TwoLetterISORegionName:       US
   CurrencySymbol:               $
   ISOCurrencySymbol:            USD

The two RegionInfo instances are equal.

*/
Imports System.Globalization


Public Class SamplesRegionInfo   

   Public Shared Sub Main()

      ' Displays the property values of the RegionInfo for "US".
      Dim myRI1 As New RegionInfo("US")
      Console.WriteLine("   Name:                         {0}", myRI1.Name)
      Console.WriteLine("   DisplayName:                  {0}", myRI1.DisplayName)
      Console.WriteLine("   EnglishName:                  {0}", myRI1.EnglishName)
      Console.WriteLine("   IsMetric:                     {0}", myRI1.IsMetric)
      Console.WriteLine("   ThreeLetterISORegionName:     {0}", myRI1.ThreeLetterISORegionName)
      Console.WriteLine("   ThreeLetterWindowsRegionName: {0}", myRI1.ThreeLetterWindowsRegionName)
      Console.WriteLine("   TwoLetterISORegionName:       {0}", myRI1.TwoLetterISORegionName)
      Console.WriteLine("   CurrencySymbol:               {0}", myRI1.CurrencySymbol)
      Console.WriteLine("   ISOCurrencySymbol:            {0}", myRI1.ISOCurrencySymbol)
      Console.WriteLine()

      ' Compares the RegionInfo above with another RegionInfo created using CultureInfo.
      Dim myRI2 As New RegionInfo(New CultureInfo("en-US", False).LCID)
      If myRI1.Equals(myRI2) Then
         Console.WriteLine("The two RegionInfo instances are equal.")
      Else
         Console.WriteLine("The two RegionInfo instances are NOT equal.")
      End If 

   End Sub

End Class


'This code produces the following output.

'

'   Name:                         US

'   DisplayName:                  United States

'   EnglishName:                  United States

'   IsMetric:                     False

'   ThreeLetterISORegionName:     USA

'   ThreeLetterWindowsRegionName: USA

'   TwoLetterISORegionName:       US

'   CurrencySymbol:               $

'   ISOCurrencySymbol:            USD

'

'The two RegionInfo instances are equal.


注解

与类不同RegionInfo , 类不表示用户首选项, 且不依赖于用户的语言或区域性。 CultureInfoUnlike the CultureInfo class, the RegionInfo class does not represent user preferences and does not depend on the user's language or culture.

与 RegionInfo 对象关联的名称Names Associated with a RegionInfo Object

RegionInfo对象的名称是在 ISO 3166 中为国家/地区定义的由两个字母组成的代码之一。The name of a RegionInfo object is one of the two-letter codes defined in ISO 3166 for country/region. Case 并不重要。Case is not significant. Name、和属性ThreeLetterISORegionName以大写形式返回相应的代码。 TwoLetterISORegionNameThe Name, TwoLetterISORegionName, and ThreeLetterISORegionName properties return the appropriate codes in uppercase. 有关当前RegionInfo名称列表, 请参阅 ISO 网站上的英语国家/地区名称和代码元素For the current list of RegionInfo names, see English country names and code elements on the ISO website.

实例化 RegionInfo 对象Instantiating a RegionInfo Object

若要实例RegionInfo化对象, 请向RegionInfo(String)构造函数传递两个字母的区域名称 (如 "US") 作为美国或特定区域性的名称 (例如 "en-us" 表示英语 (美国)。To instantiate a RegionInfo object, you pass the RegionInfo(String) constructor either a two-letter region name, such as "US" for the United States, or the name of a specific culture, such as "en-US" for English (United States). 但是, 我们建议你使用特定的区域性名称而不是两个字母的区域名称, 因为RegionInfo对象不是完全独立于语言的。However, we recommend that you use a specific culture name instead of a two-letter region name, because a RegionInfo object is not completely language-independent. RegionInfo个属性, DisplayName包括NativeName、和CurrencyNativeName, 它们依赖于区域性名称。Several RegionInfo properties, including DisplayName, NativeName, and CurrencyNativeName, depend on culture names.

下面的示例说明了表示华南RegionInfo的三个对象的属性值的差异。The following example illustrates the difference in RegionInfo property values for three objects that represent Belgium. 第一个仅从区域名称 (为) 实例化, 第二个和第三个实例化区域性名称 (fr 表示法语 (比利时), nl 为荷兰语 (比利时))。The first is instantiated from a region name (BE) only, while the second and third are instantiated from culture names (fr-BE for French (Belgium) and nl-BE for Dutch (Belgium), respectively). 该示例使用反射来检索每个RegionInfo对象的属性值。The example uses reflection to retrieve the property values of each RegionInfo object.

using System;
using System.Globalization;
using System.Reflection;

public class Example
{
   public static void Main()
   {
      // Instantiate three Belgian RegionInfo objects.
      RegionInfo BE = new RegionInfo("BE");
      RegionInfo frBE = new RegionInfo("fr-BE");
      RegionInfo nlBE = new RegionInfo("nl-BE");

      RegionInfo[] regions = { BE, frBE, nlBE };
      PropertyInfo[] props = typeof(RegionInfo).GetProperties(BindingFlags.Instance | BindingFlags.Public);
      
      Console.WriteLine("{0,-30}{1,18}{2,18}{3,18}\n", 
                        "RegionInfo Property", "BE", "fr-BE", "nl-BE");
      foreach (var prop in props) {
         Console.Write("{0,-30}", prop.Name);
         foreach (var region in regions)
            Console.Write("{0,18}", prop.GetValue(region, null));

         Console.WriteLine();
      }
   }
}
// The example displays the following output:
//    RegionInfo Property                           BE             fr-BE             nl-BE
//    
//    Name                                          BE             fr-BE             nl-BE
//    EnglishName                              Belgium           Belgium           Belgium
//    DisplayName                              Belgium           Belgium           Belgium
//    NativeName                                België          Belgique            België
//    TwoLetterISORegionName                        BE                BE                BE
//    ThreeLetterISORegionName                     BEL               BEL               BEL
//    ThreeLetterWindowsRegionName                 BEL               BEL               BEL
//    IsMetric                                    True              True              True
//    GeoId                                         21                21                21
//    CurrencyEnglishName                         Euro              Euro              Euro
//    CurrencyNativeName                          euro              euro              euro
//    CurrencySymbol                                 €                 €                 €
//    ISOCurrencySymbol                            EUR               EUR               EUR
Imports System.Globalization
Imports System.Reflection

Module Example
   Public Sub Main()
      ' Instantiate three Belgian RegionInfo objects.
      Dim BE As New RegionInfo("BE")
      Dim frBE As New RegionInfo("fr-BE")
      Dim nlBE As New RegionInfo("nl-BE")

      Dim regions() As RegionInfo = { BE, frBE, nlBE }
      Dim props() As PropertyInfo = GetType(RegionInfo).GetProperties(BindingFlags.Instance Or BindingFlags.Public)
      
      Console.WriteLine("{0,-30}{1,18}{2,18}{3,18}", 
                        "RegionInfo Property", "BE", "fr-BE", "nl-BE")
      Console.WriteLine()
      For Each prop As PropertyInfo In props
         Console.Write("{0,-30}", prop.Name)
         For Each region In regions
            Console.Write("{0,18}", prop.GetValue(region, Nothing))
         Next
         Console.WriteLine()
      Next
   End Sub
End Module
' The example displays the following output:
'    RegionInfo Property                           BE             fr-BE             nl-BE
'    
'    Name                                          BE             fr-BE             nl-BE
'    EnglishName                              Belgium           Belgium           Belgium
'    DisplayName                              Belgium           Belgium           Belgium
'    NativeName                                België          Belgique            België
'    TwoLetterISORegionName                        BE                BE                BE
'    ThreeLetterISORegionName                     BEL               BEL               BEL
'    ThreeLetterWindowsRegionName                 BEL               BEL               BEL
'    IsMetric                                    True              True              True
'    GeoId                                         21                21                21
'    CurrencyEnglishName                         Euro              Euro              Euro
'    CurrencyNativeName                          euro              euro              euro
'    CurrencySymbol                                 €                 €                 €
'    ISOCurrencySymbol                            EUR               EUR               EUR

在如下所示的方案中, 当您实例化RegionInfo对象时, 请使用区域性名称 (而不是国家/地区名称):In scenarios such as the following, use culture names instead of country/region names when you instantiate a RegionInfo object:

  • 当语言名称主要重要时。When the language name is of primary importance. 例如, 对于 EN-US 区域性名称, 你可能希望你的应用程序显示 "Estados Unidos" 而不是 "美国"。For example, for the es-US culture name, you'll probably want your application to display "Estados Unidos" instead of "United States". 无论使用何种语言, 单独使用国家/地区名称 (US) 都将产生 "美国", 因此应改为使用区域性名称。Using the country/region name (US) alone yields "United States" regardless of the language, so you should work with the culture name instead.

  • 必须考虑脚本差异。When script differences must be considered. 例如, 国家/地区 AZ 处理具有 AZ-Latn-AZ 和 AZ-Cyrl-AZ 的阿塞拜疆文化, 并且对于此国家/地区, 拉丁语和西里尔文脚本可能会有很大的不同。For example, the country/region AZ deals with Azerbaijani cultures that have the names az-Latn-AZ and az-Cyrl-AZ, and the Latin and Cyrillic scripts can be very different for this country/region.

  • 维护详细信息非常重要。When maintenance of detail is important. RegionInfo成员返回的值可能不同, 具体取决于RegionInfo是否使用区域性名称或区域名称实例化对象。The values returned by RegionInfo members can differ depending on whether the RegionInfo object was instantiated by using a culture name or a region name. 例如, 下表列出了使用 "us" 区域、"en-us RegionInfo " 区域性和 "en-us" 区域性对对象进行实例化时返回值之间的差异。For example, the following table lists the differences in return values when a RegionInfo object is instantiated by using the "US" region, the "en-US" culture, and the "es-US" culture.

    成员Member 反馈"US" "en-us""en-US" "es-US""es-US"
    CurrencyNativeName 美元US Dollar 美元US Dollar Dólar de。UU.Dólar de EE.UU.
    Name USUS en-USen-US eses-US
    NativeName 美国United States 美国United States Estados UnidosEstados Unidos
    ToString USUS en-USen-US eses-US

构造函数

RegionInfo(Int32)

基于与指定的区域性标识符关联的国家/地区初始化 RegionInfo 类的一个新实例。Initializes a new instance of the RegionInfo class based on the country/region associated with the specified culture identifier.

RegionInfo(String)

基于按名称指定的国家/地区或特定区域性初始化 RegionInfo 类的一个新实例。Initializes a new instance of the RegionInfo class based on the country/region or specific culture, specified by name.

属性

CurrencyEnglishName

获取该国家/地区中使用的货币的英文名称。Gets the name, in English, of the currency used in the country/region.

CurrencyNativeName

获取该国家/地区中使用的货币名称,它使用该国家/地区的本地语言格式表示。Gets the name of the currency used in the country/region, formatted in the native language of the country/region.

CurrencySymbol

获取与国家/地区关联的货币符号。Gets the currency symbol associated with the country/region.

CurrentRegion

获取表示当前线程所使用的国家/地区的 RegionInfoGets the RegionInfo that represents the country/region used by the current thread.

DisplayName

获取以 .NET Framework 本地化版本语言表示的国家/地区的全名。Gets the full name of the country/region in the language of the localized version of .NET Framework.

EnglishName

获取以英文表示的国家/地区的全名。Gets the full name of the country/region in English.

GeoId

获取地理区域、国家/地区、城市或地点的唯一标识号。Gets a unique identification number for a geographical region, country, city, or location.

IsMetric

获取一个值,该值指示该国家/地区是否使用公制进行度量。Gets a value indicating whether the country/region uses the metric system for measurements.

ISOCurrencySymbol

获取与国家/地区关联的由三个字符组成的 ISO 4217 货币符号。Gets the three-character ISO 4217 currency symbol associated with the country/region.

Name

获取当前 RegionInfo 对象的名称或 ISO 3166 双字母国家/地区代码。Gets the name or ISO 3166 two-letter country/region code for the current RegionInfo object.

NativeName

获取一个国家/地区的名称,它使用该国家/地区的本地语言格式表示。Gets the name of a country/region formatted in the native language of the country/region.

ThreeLetterISORegionName

获取在 ISO 3166 中定义的由三个字母组成的国家/地区代码。Gets the three-letter code defined in ISO 3166 for the country/region.

ThreeLetterWindowsRegionName

获取 Windows 分配给此 RegionInfo 所表示国家/地区的由三个字母组成的代码。Gets the three-letter code assigned by Windows to the country/region represented by this RegionInfo.

TwoLetterISORegionName

获取在 ISO 3166 中定义的由两个字母组成的国家/地区代码。Gets the two-letter code defined in ISO 3166 for the country/region.

方法

Equals(Object)

确定指定的对象与当前 RegionInfo 是否为同一实例。Determines whether the specified object is the same instance as the current RegionInfo.

GetHashCode()

用作当前 RegionInfo 的哈希函数,适合用在哈希算法和数据结构(如哈希表)中。Serves as a hash function for the current RegionInfo, suitable for hashing algorithms and data structures, such as a hash table.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个字符串,它包含区域性名称或 ISO 3166 中为当前 RegionInfo 指定的双字母国家/地区代码。Returns a string containing the culture name or ISO 3166 two-letter country/region codes specified for the current RegionInfo.

适用于

另请参阅