Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

RegionInfo Constructor (String)

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

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

public RegionInfo (
	string name
)
public RegionInfo (
	String name
)
public function RegionInfo (
	name : String
)

Parameters

name

A string containing one of the two-letter codes defined in ISO 3166 for country/region.

-or-

A string containing the culture name for a specific culture, custom culture, or Windows-only culture. If the culture name is in the RFC 1766 format, which consists of language and region, specify entire culture name, not just the region.

Exception typeCondition

ArgumentNullException

name is a null reference (Nothing in Visual Basic).

ArgumentException

name is not a valid country/region name or specific culture name.

The RegionInfo name is one of the two-letter codes defined in ISO 3166 for country/region, or a specific, custom, or Windows-only culture name. Case is not significant; however, the Name, the TwoLetterISORegionName, and the ThreeLetterISORegionName properties return the specified code or culture name in uppercase.

The predefined RegionInfo names are listed in the RegionInfo class topic.

Culture names that follow the RFC 1766 standard are in the format "<languagecode2>-<country/regioncode2>", where <languagecode2> is a lowercase two-letter code derived from ISO 639-1 and <country/regioncode2> is an uppercase two-letter code derived from ISO 3166. For example, U.S. English is "en-US". In cases where a two-letter language code is not available, the three-letter code derived from ISO 639-2 is used; for example, the three-letter code "div" is used for cultures that use the Dhivehi language. Some culture names have suffixes that specify the script; for example, "-Cyrl" specifies the Cyrillic script, "-Latn" specifies the Latin script. The predefined CultureInfo names are listed in the CultureInfo class topic.

The cultures are generally grouped into three sets: the invariant culture, the neutral cultures, and the specific cultures.

The invariant culture is culture-insensitive. You can specify the invariant culture by name using an empty string ("") or by its culture identifier 0x007F. InvariantCulture retrieves an instance of the invariant culture. It is associated with the English language but not with any country/region. It can be used in almost any method in the Globalization namespace that requires a culture. If a security decision depends on a string comparison or a case-change operation, use the InvariantCulture to ensure that the behavior will be consistent regardless of the culture settings of the system. However, the invariant culture must be used only by processes that require culture-independent results, such as system services; otherwise, it produces results that might be linguistically incorrect or culturally inappropriate.

A neutral culture is a culture that is associated with a language but not with a country/region. A specific culture is a culture that is associated with a language and a country/region. For example, "fr" is a neutral culture and "fr-FR" is a specific culture. Note that "zh-CHS" (Simplified Chinese) and "zh-CHT" (Traditional Chinese) are neutral cultures.

Notes to Callers This constructor accepts only specific cultures; however, some neutral culture names are the same as country/region codes, and this constructor will not throw ArgumentException when those names are used.  Therefore, before constructing the RegionInfo with culture names as the value of name, you must verify that the culture is not the InvariantCulture and that the CultureInfo.IsNeutralCulture property for that culture is false.

The following code example compares two instances of RegionInfo that were created differently.

using System;
using System.Globalization;

public class SamplesRegionInfo  {

   public static void Main()  {

      // Creates a RegionInfo using the ISO 3166 two-letter code.
      RegionInfo myRI1 = new RegionInfo( "US" );

      // Creates a RegionInfo using a CultureInfo.LCID.
      RegionInfo myRI2 = new RegionInfo( new CultureInfo("en-US",false).LCID );

      // Compares the two instances.
      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.

The two RegionInfo instances are equal.

*/

import System.*;
import System.Globalization.*;

public class SamplesRegionInfo
{   
    public static void main(String[] args)
    {
        // Creates a RegionInfo using the ISO 3166 two-letter code.
        RegionInfo myRI1 =  new RegionInfo("US");

        // Creates a RegionInfo using a CultureInfo.LCID.
        RegionInfo myRI2 =  
            new RegionInfo((new CultureInfo("en-US", false)).get_LCID());

        // Compares the two instances.
        if (myRI1.Equals(myRI2)) {
            Console.WriteLine("The two RegionInfo instances are equal.");
        }
        else {
            Console.WriteLine("The two RegionInfo instances are NOT equal.");
        }
    } //main
} //SamplesRegionInfo

/*
This code produces the following output.

The two RegionInfo instances are equal.

*/

The following code example creates instances of RegionInfo using culture names.

using System;
using System.Globalization;

public class SamplesRegionInfo  {

   public static void Main()  {

      // Creates an array containing culture names.
      String[] myCultures = new String[]  { "", "ar", "ar-DZ", "en", "en-US" };

      // Creates a RegionInfo for each of the culture names.
      //    Note that "ar" is the culture name for the neutral culture "Arabic",
      //    but it is also the region name for the country/region "Argentina";
      //    therefore, it does not fail as expected.
      Console.WriteLine( "Without checks..." );
      foreach ( String cul in myCultures )  {
         try  {
            RegionInfo myRI = new RegionInfo( cul );
         }
         catch ( ArgumentException e )  {
            Console.WriteLine( e.ToString() );
         }
      }

      Console.WriteLine();

      Console.WriteLine( "Checking the culture names first..." );
      foreach ( String cul in myCultures )  {
         if ( cul == "" )  {
            Console.WriteLine( "The culture is the invariant culture." );
         }
         else  {
            CultureInfo myCI = new CultureInfo( cul, false );
            if ( myCI.IsNeutralCulture )
               Console.WriteLine( "The culture {0} is a neutral culture.", cul );
            else   {
               Console.WriteLine( "The culture {0} is a specific culture.", cul );
               try  {
                  RegionInfo myRI = new RegionInfo( cul );
               }
               catch ( ArgumentException e )  {
                  Console.WriteLine( e.ToString() );
               }
            }
         }
      }

   }

}

/*
This code produces the following output.

Without checks...
System.ArgumentException: Region name '' is not supported.
Parameter name: name
   at System.Globalization.RegionInfo..ctor(String name)
   at SamplesRegionInfo.Main()
System.ArgumentException: Region name 'en' is not supported.
Parameter name: name
   at System.Globalization.CultureTableRecord..ctor(String regionName, Boolean useUserOverride)
   at System.Globalization.RegionInfo..ctor(String name)
   at SamplesRegionInfo.Main()

Checking the culture names first...
The culture is the invariant culture.
The culture ar is a neutral culture.
The culture ar-DZ is a specific culture.
The culture en is a neutral culture.
The culture en-US is a specific culture.

*/

import System.*;
import System.Globalization.*;

public class SamplesRegionInfo
{
    public static void main(String[] args)
    {
        // Creates an array containing culture names.
        String myCultures[] = new String[] { "", "ar", "ar-DZ", "en", "en-US" };
        
        // Creates a RegionInfo for each of the culture names.
        // Note that "ar" is the culture name for the neutral culture "Arabic",
        // but it is also the region name for the country/region "Argentina";
        // therefore, it does not fail as expected.
        Console.WriteLine("Without checks...");
        for (int iCtr = 0; iCtr < myCultures.get_Length(); iCtr++) {
            String cul = (String)myCultures.get_Item(iCtr);
            try {
                RegionInfo myRI = new RegionInfo(cul);
            }
            catch (ArgumentException e) {
                Console.WriteLine(e.ToString());
            }
        }
        Console.WriteLine();
        Console.WriteLine("Checking the culture names first...");
        for (int iCtr = 0; iCtr < myCultures.get_Length(); iCtr++) {
            String cul = (String)myCultures.get_Item(iCtr);
            if (cul.Equals("")) {
                Console.WriteLine("The culture is the invariant culture.");
            }
            else {
                CultureInfo myCI = new CultureInfo(cul, false);
                if (myCI.get_IsNeutralCulture()) {
                    Console.WriteLine("The culture {0} is a neutral culture.", 
                        cul);
                }
                else {
                    Console.WriteLine("The culture {0} is a specific culture.",
                        cul);
                    try {
                        RegionInfo myRI = new RegionInfo(cul);
                    }
                    catch (ArgumentException e) {
                        Console.WriteLine(e.ToString());
                    }
                }
            }
        }
    } //main
} //SamplesRegionInfo

/*
This code produces the following output.

Without checks...
System.ArgumentException: Region name '' is not supported.
Parameter name: name
   at System.Globalization.RegionInfo..ctor(String name)
   at SamplesRegionInfo.main(String[] args)
System.ArgumentException: Region name 'en' is not supported.
Parameter name: name
   at System.Globalization.CultureTableRecord..ctor(String regionName, 
   Boolean useUserOverride)
   at System.Globalization.RegionInfo..ctor(String name)
   at SamplesRegionInfo.Main()

Checking the culture names first...
The culture is the invariant culture.
The culture ar is a neutral culture.
The culture ar-DZ is a specific culture.
The culture en is a neutral culture.
The culture en-US is a specific culture.

*/

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft