.NET Framework Class Library
RegionInfo Constructor (Int32)

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

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

Syntax

Visual Basic (Declaration)
Public Sub New ( _
    culture As Integer _
)
Visual Basic (Usage)
Dim culture As Integer

Dim instance As New RegionInfo(culture)
C#
public RegionInfo (
    int culture
)
C++
public:
RegionInfo (
    int culture
)
J#
public RegionInfo (
    int culture
)
JScript
public function RegionInfo (
    culture : int
)

Parameters

culture

A culture identifier.

Exceptions

Exception typeCondition

ArgumentException

culture specifies either an invariant, custom, or neutral culture.

Remarks

The culture identifier is mapped to the corresponding National Language Support (NLS) locale identifier. A list of culture identifiers is provided in the CultureInfo class topic.

The name of the new RegionInfo object is the ISO 3166 2-letter code for the region, not the 2-letter language and region codes. For example, the culture identifier for the English-United States culture, which is 0x409, yields a region name of "US", not "en-US".

Example

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

Visual Basic
Imports System
Imports System.Globalization


Public Class SamplesRegionInfo   

   Public Shared Sub Main()

      ' Creates a RegionInfo using the ISO 3166 two-letter code.
      Dim myRI1 As New RegionInfo("US")

      ' Creates a RegionInfo using a CultureInfo.LCID.
      Dim myRI2 As New RegionInfo(New CultureInfo("en-US", False).LCID)

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

End Class 'SamplesRegionInfo 


'This code produces the following output.

'

'The two RegionInfo instances are equal.

C#
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.

*/
C++
using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Creates a RegionInfo using the ISO 3166 two-letter code.
   RegionInfo^ myRI1 = gcnew RegionInfo( "US" );
   
   // Creates a RegionInfo using a CultureInfo.LCID.
   RegionInfo^ myRI2 = gcnew RegionInfo( (gcnew 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.

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

*/
Platforms

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.

Version Information

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
See Also

Tags :


Community Content

Shawn Steele [MSFT]
Try to use a full culture id when constructing RegionInfo objects

You can use a RegionInfo() object with a region name in the constructor, like "US", however that doesn't always provide appropriate results.  The RegionInfo properties, such as DisplayName for example, depend on the language and culture being used.  So often it is more interesting to construct a RegionInfo from a full culture name like "en-US" than from just the region name.

Consider for example a locale like "es-US" on Windows Vista.  In that case, you'd probably want a display name of "Estados Unitos" instead of "United States".  In other cases there could be script differences, ie "AZ" has the variations of "az-Latn-AZ" and "az-Cyrl-AZ".  The Latin and Cyrillic scripts can be very different: Azərbaycanca vs Азәрбајҹан.

Lastly, if you have a specific culture, like "en-US", then its nice to keep the detail around.  If you have to try and create a new CultureInfo or RegionInfo object from just the "en" or "US" name you have lost information.  It is best to use the most specific form possible when practical.

Tags :

Page view tracker