Duration (Pacific Standard Time):
To (Pacific Standard Time):
Impact:
  • None
User Action:
  • None
.NET Framework Class Library

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 Sub New ( _
	name As String _
)
Dim name As String 

Dim instance As New RegionInfo(name)

Parameters

name
Type: System.String

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 Condition
ArgumentNullException

name is null.

ArgumentException

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

The name parameter 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 or country/region codes. However, some neutral culture names are the same as country/region codes. In this case, name is interpreted as a country/region code rather than a neutral culture name, and this constructor does not throw an ArgumentException.

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

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.

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

Imports System.Globalization

Public Class SamplesRegionInfo
    Public Shared Sub Main()
        ' Creates an array containing culture names. 
        Dim myCultures() As 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 Each culture In  myCultures
            Try 
                Dim myRI As New RegionInfo(culture)
            Catch e As ArgumentException
                Console.WriteLine(e.ToString())
            End Try 
        Next

        Console.WriteLine()

        Console.WriteLine("Checking the culture names first...")
        For Each culture In  myCultures
            If culture = "" Then
                Console.WriteLine("The culture is the invariant culture.")
            Else 
                Dim myCI As New CultureInfo(culture, False)
                If myCI.IsNeutralCulture Then
                    Console.WriteLine("The culture {0} is a neutral culture.", culture)
                Else
                    Console.WriteLine("The culture {0} is a specific culture.", culture)
                    Try 
                        Dim myRI As New RegionInfo(culture)
                    Catch e As ArgumentException
                        Console.WriteLine(e.ToString())
                    End Try 
                End If 
            End If 
        Next 
    End Sub   
End Class  
'The example displays 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.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0