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.


備註

不同于 CultureInfo 類別,RegionInfo 類別不代表使用者喜好設定,而且不會相依于使用者的語言或文化特性。Unlike 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 is not significant. NameTwoLetterISORegionNameThreeLetterISORegionName 屬性會以大寫傳回適當的代碼。The 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 屬性,包括 DisplayNameNativeNameCurrencyNativeName,取決於文化特性名稱。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. 例如,針對 es 文化特性名稱,您可能會想要讓應用程式顯示 "Estados Unidos",而不是 "美國"。For example, for the es-US culture name, you'll probably want your application to display "Estados Unidos" instead of "United States". 無論語言為何,使用國家/地區名稱(美國)都會產生「美國」,因此您應該改為使用文化特性名稱。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" 文化特性和 "es" 文化特性來具現化 RegionInfo 物件時,傳回值中的差異。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""es-US"
    CurrencyNativeName 美元US Dollar 美元US Dollar Dólar de EE。UU.Dólar de EE.UU.
    Name USUS zh-TWen-US es-USes-US
    NativeName 美國United States 美國United States Estados UnidosEstados Unidos
    ToString USUS zh-TWen-US es-USes-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

取得 RegionInfo,表示目前執行緒所使用的國家/地區。Gets 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 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回字串,其中包含針對目前 RegionInfo 所指定的文化特性名稱或 ISO 3166 兩個字母國家/地區代碼。Returns a string containing the culture name or ISO 3166 two-letter country/region codes specified for the current RegionInfo.

適用於

另請參閱