RegionInfo Constructor

Initializes a new instance of the RegionInfo class for a particular country/region based on its full culture name.

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

[SecuritySafeCriticalAttribute]
public RegionInfo(
	string name
)

Parameters

name
Type: System.String
A string containing the full culture name for a specific culture.

ExceptionCondition
ArgumentNullException

name is null.

ArgumentException

name is a country/region name.

-or-

name is the name of a neutral culture.

-or-

name is not a valid culture name.

The specified name must be the name of a specific culture. It cannot be the name of a neutral culture. For example, en-US or en-ZW are valid strings to pass to the name parameter; en is not. Case is not significant. The predefined culture names are listed in the CultureInfo class topic.

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


using System;
using System.Globalization;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Creates a RegionInfo using the es-US culture name.
      RegionInfo myRI1 = new RegionInfo("es-US");

      // Creates a RegionInfo using a CultureInfo Name property
      RegionInfo myRI2 = new RegionInfo(new CultureInfo("en-US").Name);

      // Compares the two instances.
      if (myRI1.Equals(myRI2))
         outputBlock.Text += "The two RegionInfo instances are equal." + "\n";
      else
         outputBlock.Text += "The two RegionInfo instances are NOT equal." + "\n";
   }
}
/*
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 Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {

      // 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.
      outputBlock.Text += "Without checks..." + "\n";
      foreach (String cul in myCultures)
      {
         try
         {
            RegionInfo myRI = new RegionInfo(cul);
         }
         catch (ArgumentException e)
         {
            outputBlock.Text += e.ToString() + "\n";
         }
      }

      outputBlock.Text += "\n";

      outputBlock.Text += "Checking the culture names first..." + "\n";
      foreach (String cul in myCultures)
      {
         if (cul == "")
         {
            outputBlock.Text += "The culture is the invariant culture." + "\n";
         }
         else
         {
            CultureInfo myCI = new CultureInfo(cul);
            if (myCI.IsNeutralCulture)
               outputBlock.Text += String.Format("The culture '{0}' is a neutral culture.", cul) + "\n";
            else
            {
               outputBlock.Text += String.Format("The culture '{0}' is a specific culture.", cul) + "\n";
               try
               {
                  RegionInfo myRI = new RegionInfo(cul);
               }
               catch (ArgumentException e)
               {
                  outputBlock.Text += e.ToString() + "\n";
               }
            }
         }
      }
   }
}
/*
This example produces the following output.
   Without checks...
   System.ArgumentException: The region name ar should not correspond to neutral culture; a specific culture is required.
   Parameter name: name
      at System.Globalization.RegionInfo..ctor(String name)
      at Example.Demo(TextBlock outputBlock)
   System.ArgumentException: The region name ar should not correspond to neutral culture; a specific culture is required.
   Parameter name: name
      at System.Globalization.RegionInfo..ctor(String name)
      at Example.Demo(TextBlock outputBlock)

   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.
*/


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show: