次の方法で共有


RegionInfo コンストラクタ (String)

名前で指定された国/地域または特定カルチャに基づいて、RegionInfo クラスの新しいインスタンスを初期化します。

名前空間: System.Globalization
アセンブリ: mscorlib (mscorlib.dll 内)

構文

'宣言
Public Sub New ( _
    name As String _
)
'使用
Dim name As String

Dim instance As New RegionInfo(name)
public RegionInfo (
    string name
)
public:
RegionInfo (
    String^ name
)
public RegionInfo (
    String name
)
public function RegionInfo (
    name : String
)

パラメータ

  • name
    ISO 3166 で定義された、国/地域の 2 文字のコードの 1 つを含む文字列。

    または

    特定カルチャ、カスタム カルチャ、または Windows 専用カルチャのカルチャ名を含む文字列。カルチャ名が、言語と地域で構成される RFC 1766 形式の場合は、地域だけでなくカルチャ名全体を指定します。

例外

例外の種類 条件

ArgumentNullException

name が null 参照 (Visual Basic では Nothing) です。

ArgumentException

name が有効な国/地域名または特定カルチャ名ではありません。

解説

RegionInfo 名は、ISO 3166 で国/地域に対して定義されている 2 文字のコードのいずれか、特定カルチャ名、カスタム カルチャ名、または Windows 専用カルチャ名になります。大文字と小文字の区別は特に重要ではありませんが、NameTwoLetterISORegionNameThreeLetterISORegionName の各プロパティは、指定されたコードまたはカルチャ名を大文字で返します。

定義済みの RegionInfo の名前は、RegionInfo クラスのトピックに一覧表示されています。

RFC 1766 標準に準拠したカルチャ名は、"<languagecode2>-<country/regioncode2>" という形式になります。<languagecode2> は ISO 639-1 に基づく 2 桁の小文字コードであり、<country/regioncode2> は ISO 3166 に基づく 2 桁の大文字コードです。たとえば、米国の英語は "en-US" となります。2 文字の言語コードが存在しない場合は、ISO 639-2 から派生した 3 文字のコードを使用します。たとえば、3 文字のコード "div" は、ディベヒ語を使用するカルチャに対して使用します。一部のカルチャ名には、文字の種類を示すサフィックスが付きます。たとえば、"-Cyrl" はキリル文字を示し、"-Latn" はラテン文字を示します。定義済みの CultureInfo の名前は、CultureInfo クラスのトピックに一覧表示されています。

カルチャは、通常、インバリアント カルチャ、ニュートラル カルチャ、および特定カルチャの 3 つのセットにグループ化されます。

インバリアント カルチャは、カルチャ固有の設定ではありません。空の文字列 ("") を使用した名前で、またはカルチャ識別子 0x007F を使用することによって、インバリアント カルチャを指定できます。InvariantCulture は、インバリアント カルチャのインスタンスを取得します。この設定は、英語と関連付けられていますが、国や地域には関連付けられていません。これは、カルチャを必要とする Globalization 名前空間のほとんどのメソッドで使用できます。セキュリティの決定が文字列の比較や大文字/小文字の変換操作に依存する場合は、システムのカルチャ設定にかかわらず一定の動作を保証するために InvariantCulture を使用してください。ただし、インバリアント カルチャは、システム サービスなど、カルチャに依存しない結果を必要とするプロセスでだけ使用する必要があります。それ以外の場合に使用すると、言語として正しくない、またはカルチャに対して不適切な結果が生じます。

ニュートラル カルチャは、国や地域ではなく、言語に関連付けられているカルチャです。特定のカルチャは、1 つの言語、および 1 つの国または地域に関連付けられたカルチャです。たとえば、"fr" はニュートラル カルチャであり、"fr-FR" は特定のカルチャです。"zh-CHS" (簡体字中国語) および "zh-CHT" (繁体字中国語) はニュートラル カルチャです。

呼び出し時の注意 このコンストラクタは、特定のカルチャのみを受け入れます。ただし、一部のニュートラル カルチャ名は国/地域コードと同じであり、その名前が使用される場合、このコンストラクタは ArgumentException をスローしません。したがって、name の値としてカルチャ名を使用して RegionInfo を構築する前に、カルチャが InvariantCulture ではなく、そのカルチャの CultureInfo.IsNeutralCulture プロパティが false であることを確認する必要があります。

使用例

異なる方法で作成された RegionInfo の 2 つのインスタンスを比較する例を次に示します。

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.

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.

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

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

*/

カルチャ名を使用して RegionInfo のインスタンスを作成するコード例を次に示します。

Imports System
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 cul 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 cul In  myCultures
            Try
                Dim myRI As New RegionInfo(cul)
            Catch e As ArgumentException
                Console.WriteLine(e.ToString())
            End Try
        Next cul

        Console.WriteLine()

        Console.WriteLine("Checking the culture names first...")
        For Each cul In  myCultures
            If cul = "" Then
                Console.WriteLine("The culture is the invariant culture.")
            Else
                Dim myCI As New CultureInfo(cul, False)
                If myCI.IsNeutralCulture Then
                    Console.WriteLine("The culture {0} is a neutral culture.", cul)
                Else
                    Console.WriteLine("The culture {0} is a specific culture.", cul)
                    Try
                        Dim myRI As New RegionInfo(cul)
                    Catch e As ArgumentException
                        Console.WriteLine(e.ToString())
                    End Try
                End If
            End If
        Next cul

    End Sub 'Main 

End Class 'SamplesRegionInfo


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

      Console.WriteLine();

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

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

*/
import System.*;
import System.Globalization.*;

public class SamplesRegionInfo
{
    public static void main(String[] args)
    {
        // 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...");
        for (int iCtr = 0; iCtr < myCultures.get_Length(); iCtr++) {
            String cul = (String)myCultures.get_Item(iCtr);
            try {
                RegionInfo myRI = new RegionInfo(cul);
            }
            catch (ArgumentException e) {
                Console.WriteLine(e.ToString());
            }
        }
        Console.WriteLine();
        Console.WriteLine("Checking the culture names first...");
        for (int iCtr = 0; iCtr < myCultures.get_Length(); iCtr++) {
            String cul = (String)myCultures.get_Item(iCtr);
            if (cul.Equals("")) {
                Console.WriteLine("The culture is the invariant culture.");
            }
            else {
                CultureInfo myCI = new CultureInfo(cul, false);
                if (myCI.get_IsNeutralCulture()) {
                    Console.WriteLine("The culture {0} is a neutral culture.", 
                        cul);
                }
                else {
                    Console.WriteLine("The culture {0} is a specific culture.",
                        cul);
                    try {
                        RegionInfo myRI = new RegionInfo(cul);
                    }
                    catch (ArgumentException e) {
                        Console.WriteLine(e.ToString());
                    }
                }
            }
        }
    } //main
} //SamplesRegionInfo

/*
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(String[] args)
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 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

開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

.NET Compact Framework

サポート対象 : 2.0、1.0

参照

関連項目

RegionInfo クラス
RegionInfo メンバ
System.Globalization 名前空間