RegionInfo 생성자

정의

RegionInfo 클래스의 새 인스턴스를 초기화합니다.

오버로드

RegionInfo(Int32)

지정된 문화권 식별자와 관련된 국가/지역을 기반으로 하는 RegionInfo 클래스의 새 인스턴스를 초기화합니다.

RegionInfo(String)

이름에 의해 지정된 국가/지역 또는 특정 문화권을 기반으로 하여 RegionInfo 클래스의 새 인스턴스를 초기화합니다.

RegionInfo(Int32)

Source:
RegionInfo.cs
Source:
RegionInfo.cs
Source:
RegionInfo.cs

지정된 문화권 식별자와 관련된 국가/지역을 기반으로 하는 RegionInfo 클래스의 새 인스턴스를 초기화합니다.

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

매개 변수

culture
Int32

문화권 식별자입니다.

예외

culture는 고정, 사용자 지정 또는 중립 문화권을 지정합니다.

또는

.NET 6 이상만 해당: 환경에서 세계화 고정 모드가 사용하도록 설정됩니다.

예제

다음 코드 예제에서는 다르게 만들어진 의 RegionInfo 두 인스턴스를 비교합니다.

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.

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

설명

RegionInfo(String) 는 개체를 인스턴스화하는 데 권장되는 생성자입니다 RegionInfo . RegionInfo(Int32) 숫자 문화권 식별자를 매개 변수로 필요로 하는 생성자와 달리 해당 매개 변수는 더 읽기 쉬운 문화권 이름 또는 국가 코드입니다.

문화권 식별자는 해당 NLS(국가 언어 지원) 로캘 식별자에 매핑됩니다. 자세한 내용은 Windows LCID 참조를 참조하세요.

이 생성자를 호출하여 인스턴스화된 새 RegionInfo 개체의 속성 값 Name 은 결합된 언어 및 국가/지역 코드가 아닌 국가/지역에 대한 ISO 3166 2자 코드입니다. 예를 들어 개체가 영어(미국) 문화권에 대한 문화권 식별자 0x0409 인스턴스화되는 경우 RegionInfo 속성 값 Name 은 "US"입니다. 반면, 개체가 영어(미국) 문화권에 대한 결합된 언어 및 국가/지역 코드 en-US 로 인스턴스화되는 경우 RegionInfo 속성 값 Name 은 .NET Framework "en-US"이고 .NET Core 및 .NET 5+에서는 "US"에 불과합니다.

추가 정보

적용 대상

RegionInfo(String)

Source:
RegionInfo.cs
Source:
RegionInfo.cs
Source:
RegionInfo.cs

이름에 의해 지정된 국가/지역 또는 특정 문화권을 기반으로 하여 RegionInfo 클래스의 새 인스턴스를 초기화합니다.

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

매개 변수

name
String

해당 국가/지역에 대해 ISO 3166에 정의되어 있는 두 문자로 된 코드를 포함하는 문자열입니다.

또는

특정 문화권, 사용자 지정 문화권 또는 Windows 전용 문화권에 대한 문화권 이름을 포함하는 문자열입니다. 문화권 이름이 RFC 4646 형식이 아니면 애플리케이션에서 국가/지역뿐 아니라 전체 문화권 이름을 지정해야 합니다.

예외

name이(가) null인 경우

name이 올바른 국가/지역 이름 또는 특정 문화권 이름이 아닌 경우

또는

.NET 6 이상만 해당: 환경에서 세계화 고정 모드가 사용하도록 설정됩니다.

예제

다음 코드 예제에서는 다르게 만들어진 의 RegionInfo 두 인스턴스를 비교합니다.

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.

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

다음 코드 예제에서는 문화권 이름을 사용 하 여 인스턴스 RegionInfo 를 만듭니다.

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

namespace Sample
{
    public ref class SamplesRegionInfo  
    {
    public: 
        static void Work()  
        {

            // Creates an array containing culture names.
            array <String^>^ commonCultures = 
                {"", "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 (String^ cultureID in commonCultures)
            {   
                try  
                {
                    RegionInfo^ region = 
                    gcnew RegionInfo(cultureID);
                }

                catch (ArgumentException^ ex)  
                {
                    Console::WriteLine(ex);
                }
            }

            Console::WriteLine();

            Console::WriteLine("Checking the culture"
                " names first...");

            for each (String^ cultureID in commonCultures)
            {
                if (cultureID->Length == 0)  
                {
                    Console::WriteLine(
                        "The culture is the invariant culture.");
                }
                else  
                {
                    CultureInfo^ culture = 
                        gcnew CultureInfo(cultureID, false);
                    if (culture->IsNeutralCulture)
                    {
                        Console::WriteLine("The culture {0} is "
                            "a neutral culture.", cultureID);
                    }
                    else   
                    {
                        Console::WriteLine("The culture {0} is "
                            "a specific culture.", cultureID);
                        try  
                        {
                            RegionInfo^ region = 
                                gcnew RegionInfo(cultureID);
                        }
                        catch (ArgumentException^ ex)  
                        {
                            Console::WriteLine(ex);
                        }
                    }
                }
            } 
            Console::ReadLine();
        }
    };
}

int main()
{
    Sample::SamplesRegionInfo::Work();
    return 0;
}

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

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

설명

name 매개 변수는 국가/지역에 대해 정의된 코드 중 하나이거나 특정 사용자 지정 또는 Windows 전용 문화권 이름입니다. 대/소문자는 중요 하지 않습니다. 그러나 , TwoLetterISORegionNameThreeLetterISORegionName 속성은 Name지정된 코드 또는 문화권 이름을 대문자로 반환합니다.

미리 정의된 RegionInfo 이름은 ISO 3166: 국가 코드에 나열됩니다.

매개 변수에 국가/지역 이름이 아닌 특정 문화권의 이름을 name 제공해야 합니다. 예를 들어 영어en-US(미국) 또는 es-US 스페인어(미국)의 경우 와 CurrencyNativeName 같은 NativeName 속성이 특정 언어를 반영하기 US 때문에 가 좋습니다. az-Latn-AZ또는 az-Cyrl-AZ 은 , CurrencyNativeNameCurrencySymbol 와 같은 NativeName속성이 특정 스크립트를 반영하기 AZ 때문에 가 더 좋습니다. 미리 정의된 문화권 이름은 Windows LCID 참조에 나열됩니다.

이 생성자는 가 중립 문화권인 경우name(예: en 영어)를 throw ArgumentException 합니다.

호출자 참고

이 생성자는 특정 문화권 또는 국가/지역 코드만 허용합니다. 그러나 일부 중립 문화권 이름은 국가/지역 코드와 동일합니다. 이 경우 는 name 중립 문화권 이름이 아닌 국가/지역 코드로 해석되며 이 생성자는 을 ArgumentExceptionthrow하지 않습니다.

적용 대상