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.RegionInfo(String) Constructor

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
)
Not applicable.

Parameters

name

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

-or-

Beginning in .NET Framework version 2.0, a string containing the culture name for a specific culture, custom culture, or Windows-only culture. If the culture name is not in RFC 4646 format, your application should specify the entire culture name, not just the country/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 specified name is either one of the codes defined 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. See further discussion in Names Associated with a RegionInfo Object.

The predefined RegionInfo names are listed in the RegionInfo class topic. Prior to .NET Framework version 2.0, parameter name must be of this form.

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

Notes to Callers: This constructor accepts only specific cultures. However, some neutral culture names are the same as country/region codes, and this constructor does not throw ArgumentException when those names are used. Therefore, before constructing the RegionInfo with culture names as the value of name, your application 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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

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

Community Additions

Show:
© 2014 Microsoft