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)

'Declaration
<SecuritySafeCriticalAttribute> _
Public Sub New ( _
	name As String _
)

Parameters

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

ExceptionCondition
ArgumentNullException

name is Nothing.

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.


Imports System.Globalization


Public Class Example

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      ' Creates a RegionInfo using the es-US culture name.
      Dim myRI1 As New RegionInfo("es-US")

      ' Creates a RegionInfo using a CultureInfo name.
      Dim myRI2 As New RegionInfo(New CultureInfo("en-US").Name)

      ' Compares the two instances.
      If myRI1.Equals(myRI2) Then
         outputBlock.Text &= "The two RegionInfo instances are equal." & vbCrLf
      Else
         outputBlock.Text &= "The two RegionInfo instances are NOT equal." & vbCrLf
      End If
   End Sub
End Class 
' This example 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 Example
   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      ' 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.
      outputBlock.Text &= "Without checks..." & vbCrLf
      For Each cul As String In myCultures
         Try
            Dim myRI As New RegionInfo(cul)
         Catch e As ArgumentException
            outputBlock.Text &= e.ToString() & vbCrLf
         End Try
      Next cul

      outputBlock.Text &= vbCrLf

      outputBlock.Text &= "Checking the culture names first..." & vbCrLf
      For Each cul In myCultures
         If cul = "" Then
            outputBlock.Text &= "The culture is the invariant culture." & vbCrLf
         Else
            Dim myCI As New CultureInfo(cul)
            If myCI.IsNeutralCulture Then
               outputBlock.Text += String.Format("The culture '{0}' is a neutral culture.", cul) & vbCrLf
            Else
               outputBlock.Text += String.Format("The culture '{0}' is a specific culture.", cul) & vbCrLf
               Try
                  Dim myRI As New RegionInfo(cul)
               Catch e As ArgumentException
                  outputBlock.Text &= e.ToString() & vbCrLf
               End Try
            End If
         End If
      Next 
   End Sub  
End Class 
' 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 SilverlightApplication.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 Silverlight.Application.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: