RegionInfo Class

RegionInfo Class

 

Contains information about the country/region.

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

System.Object
  System.Globalization.RegionInfo

[SerializableAttribute]
[ComVisibleAttribute(true)]
public class RegionInfo

NameDescription
System_CAPS_pubmethodRegionInfo(Int32)

Initializes a new instance of the RegionInfo class based on the country/region associated with the specified culture identifier.

System_CAPS_pubmethodRegionInfo(String)

Initializes a new instance of the RegionInfo class based on the country/region or specific culture, specified by name.

NameDescription
System_CAPS_pubpropertyCurrencyEnglishName

Gets the name, in English, of the currency used in the country/region.

System_CAPS_pubpropertyCurrencyNativeName

Gets the name of the currency used in the country/region, formatted in the native language of the country/region.

System_CAPS_pubpropertyCurrencySymbol

Gets the currency symbol associated with the country/region.

System_CAPS_pubpropertySystem_CAPS_staticCurrentRegion

Gets the RegionInfo that represents the country/region used by the current thread.

System_CAPS_pubpropertyDisplayName

Gets the full name of the country/region in the language of the localized version of .NET Framework.

System_CAPS_pubpropertyEnglishName

Gets the full name of the country/region in English.

System_CAPS_pubpropertyGeoId

Gets a unique identification number for a geographical region, country, city, or location.

System_CAPS_pubpropertyIsMetric

Gets a value indicating whether the country/region uses the metric system for measurements.

System_CAPS_pubpropertyISOCurrencySymbol

Gets the three-character ISO 4217 currency symbol associated with the country/region.

System_CAPS_pubpropertyName

Gets the name or ISO 3166 two-letter country/region code for the current RegionInfo object.

System_CAPS_pubpropertyNativeName

Gets the name of a country/region formatted in the native language of the country/region.

System_CAPS_pubpropertyThreeLetterISORegionName

Gets the three-letter code defined in ISO 3166 for the country/region.

System_CAPS_pubpropertyThreeLetterWindowsRegionName

Gets the three-letter code assigned by Windows to the country/region represented by this RegionInfo.

System_CAPS_pubpropertyTwoLetterISORegionName

Gets the two-letter code defined in ISO 3166 for the country/region.

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is the same instance as the current RegionInfo.(Overrides Object.Equals(Object).)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as a hash function for the current RegionInfo, suitable for hashing algorithms and data structures, such as a hash table.(Overrides Object.GetHashCode().)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string containing the culture name or ISO 3166 two-letter country/region codes specified for the current RegionInfo.(Overrides Object.ToString().)

Unlike the CultureInfo class, the RegionInfo class does not represent user preferences and does not depend on the user's language or culture.

The name of a RegionInfo object is one of the two-letter codes defined in ISO 3166 for country/region. Case is not significant. The Name, TwoLetterISORegionName, and ThreeLetterISORegionName properties return the appropriate codes in uppercase. For the current list of RegionInfo names, see English country names and code elements on the ISO website.

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). 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. Several RegionInfo properties, including DisplayName, NativeName, and CurrencyNativeName, depend on culture names.

The following example illustrates the difference in RegionInfo property values for three objects that represent Belgium. 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 and nl-BE for Dutch (Belgium), respectively). 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

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. 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. 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. 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. 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"

    "es-US"

    CurrencyNativeName

    US Dollar

    US Dollar

    Dólar de EE.UU.

    Name

    US

    en-US

    es-US

    NativeName

    United States

    United States

    Estados Unidos

    ToString

    US

    en-US

    es-US

The following example demonstrates several members of the RegionInfo class.

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.

*/

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft