RegionInfo Constructors

Definitie

Initialiseert een nieuw exemplaar van de RegionInfo klasse.

Overloads

Name Description
RegionInfo(Int32)

Initialiseert een nieuw exemplaar van de RegionInfo klasse op basis van het land/de regio die is gekoppeld aan de opgegeven cultuur-id.

RegionInfo(String)

Initialiseert een nieuw exemplaar van de RegionInfo klasse op basis van het land/de regio of specifieke cultuur, opgegeven op naam.

RegionInfo(Int32)

Bron:
RegionInfo.cs
Bron:
RegionInfo.cs
Bron:
RegionInfo.cs
Bron:
RegionInfo.cs
Bron:
RegionInfo.cs

Initialiseert een nieuw exemplaar van de RegionInfo klasse op basis van het land/de regio die is gekoppeld aan de opgegeven cultuur-id.

public:
 RegionInfo(int culture);
public RegionInfo(int culture);
new System.Globalization.RegionInfo : int -> System.Globalization.RegionInfo
Public Sub New (culture As Integer)

Parameters

culture
Int32

Een cultuur-id.

Uitzonderingen

culture geeft een invariant, aangepaste of neutrale cultuur op.

– of –

.NET alleen 6+: de modus Globalization-invariant is ingeschakeld in de omgeving.

Voorbeelden

In het volgende codevoorbeeld worden twee exemplaren van RegionInfo die verschillende exemplaren vergeleken.

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.

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

End Class


'This code produces the following output.
'
'The two RegionInfo instances are equal.

Opmerkingen

RegionInfo(String) is de aanbevolen constructor voor het instantiëren van een RegionInfo object. In tegenstelling tot de RegionInfo(Int32) constructor waarvoor een numerieke cultuur-id als parameter is vereist, is de parameter een beter leesbare cultuurnaam of landcode.

De cultuur-id wordt toegewezen aan de bijbehorende NLS-landinstellings-id (National Language Support). Zie Windows LCID-verwijzing voor meer informatie.

De waarde van de Name eigenschap van het nieuwe RegionInfo object dat wordt geïnstantieerd door deze constructor aan te roepen, is de ISO 3166 2-lettercode voor het land/de regio, niet de gecombineerde taal- en land-/regiocode. Als bijvoorbeeld een RegionInfo-object wordt geïnstantieerd met de cultuur-id 0x0409 voor de Engelse cultuur (Verenigde Staten), is de waarde van de eigenschap Name 'US'. Als daarentegen een RegionInfo-object wordt geïnstantieerd met de gecombineerde taal- en land-/regiocode en-US voor de Engelse cultuur (Verenigde Staten), is de waarde van de eigenschap Name "en-US" in .NET Framework en alleen "US" in .NET Core en .NET 5+.

Zie ook

Van toepassing op

RegionInfo(String)

Bron:
RegionInfo.cs
Bron:
RegionInfo.cs
Bron:
RegionInfo.cs
Bron:
RegionInfo.cs
Bron:
RegionInfo.cs

Initialiseert een nieuw exemplaar van de RegionInfo klasse op basis van het land/de regio of specifieke cultuur, opgegeven op naam.

public:
 RegionInfo(System::String ^ name);
public RegionInfo(string name);
new System.Globalization.RegionInfo : string -> System.Globalization.RegionInfo
Public Sub New (name As String)

Parameters

name
String

Een tekenreeks die een tweeletterige code bevat die is gedefinieerd in ISO 3166 voor land/regio.

– of –

Een tekenreeks die de cultuurnaam voor een specifieke cultuur, aangepaste cultuur of Windows-only cultuur bevat. Als de cultuurnaam niet in RFC 4646-indeling staat, moet uw toepassing de volledige cultuurnaam opgeven in plaats van alleen het land/de regio.

Uitzonderingen

name is null.

name is geen geldige land-/regionaam of specifieke cultuurnaam.

– of –

.NET alleen 6+: de modus Globalization-invariant is ingeschakeld in de omgeving.

Voorbeelden

In het volgende codevoorbeeld worden twee exemplaren van RegionInfo die verschillende exemplaren vergeleken.

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.

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

End Class


'This code produces the following output.
'
'The two RegionInfo instances are equal.

In het volgende codevoorbeeld worden exemplaren gemaakt van het gebruik van RegionInfo cultuurnamen.

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 culture in myCultures)  {
         try  {
            RegionInfo myRI = new RegionInfo( culture );
         }
         catch ( ArgumentException e )  {
            Console.WriteLine( e.ToString() );
         }
      }

      Console.WriteLine();

      Console.WriteLine( "Checking the culture names first..." );
      foreach (String culture in myCultures)  {
         if ( culture == "" )  {
            Console.WriteLine("The culture is the invariant culture.");
         }
         else  {
            CultureInfo myCI = new CultureInfo( culture, false );
            if ( myCI.IsNeutralCulture )
                {
                    Console.WriteLine( "The culture {0} is a neutral culture.", culture );
                }
                else   {
               Console.WriteLine( "The culture {0} is a specific culture.", culture );
               try  {
                  RegionInfo myRI = new RegionInfo( culture );
               }
               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.

*/
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"}

        Dim culture As String

        ' 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.

Opmerkingen

De parameter name is een van de codes die zijn gedefinieerd voor land/regio, of een specifieke, aangepaste of Windows cultuurnaam. De kwestie is niet belangrijk. De Name, TwoLetterISORegionNameen ThreeLetterISORegionName eigenschappen retourneren echter de opgegeven code of cultuurnaam in hoofdletters.

De vooraf gedefinieerde RegionInfo namen worden vermeld in ISO 3166: Landcodes.

Geef de naam op van een specifieke cultuur in plaats van alleen een land-/regionaam in de name parameter. Bijvoorbeeld, en-US voor Engels (Verenigde Staten) of es-US voor Spaans (Verenigde Staten) is de voorkeur aan US omdat eigenschappen zoals NativeName en CurrencyNativeName een specifieke taal weerspiegelen. az-Latn-AZ of az-Cyrl-AZ heeft de voorkeur AZ omdat eigenschappen zoals NativeName, CurrencyNativeNameen CurrencySymbol een specifiek script weerspiegelen. De vooraf gedefinieerde cultuurnamen worden vermeld op Windows LCID-verwijzing.

Deze constructor gooit een ArgumentException als name een neutrale cultuur (zoals en voor Engels).

Notities voor bellers

Deze constructor accepteert alleen specifieke culturen of land-/regiocodes. Sommige neutrale cultuurnamen zijn echter hetzelfde als land-/regiocodes. In dit geval name wordt geïnterpreteerd als een land-/regiocode in plaats van een neutrale cultuurnaam, en deze constructor genereert ArgumentExceptiongeen .

Van toepassing op