Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Initialisiert eine neue Instanz der RegionInfo-Klasse auf der Grundlage des Landes oder der Region bzw. einer bestimmten Kultur, dessen bzw. deren Name angegeben ist.
Namespace: System.Globalization
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Sub New ( _
name As String _
)
'Usage
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
)
Parameter
name
Eine Zeichenfolge, die einen der aus zwei Buchstaben bestehenden Landes-/Regionscodes nach ISO 3166 enthält.– oder –
Eine Zeichenfolge, die Namen einer bestimmten Kultur, benutzerdefinierten Kultur oder Nur-Windows-Kultur enthält. Wenn der Kulturname dem RFC 1766-Format entspricht, das aus der Sprache und der Region besteht, muss der gesamte Kulturname angegeben werden (und nicht nur die Region).
Ausnahmen
| Ausnahmetyp | Bedingung |
|---|---|
name ist NULL (Nothing in Visual Basic). |
|
name ist weder ein Name für eine bestimmte Kultur noch ein gültiger Name für ein Land oder eine Region. |
Hinweise
Der RegionInfo-Name gehört zu den aus zwei Buchstaben bestehenden Landes- oder Regionscodes nach ISO 3166 für das Land oder die Region bzw. für eine bestimmte, benutzerdefinierte oder Nur-Windows-Kultur. Die Groß- oder Kleinschreibung ist nicht relevant. Die Eigenschaften Name, TwoLetterISORegionName und ThreeLetterISORegionName geben den entsprechenden Code oder Kulturnamen jedoch in Großbuchstaben zurück.
Die vordefinierten RegionInfo-Namen sind unter dem Thema RegionInfo-Klasse aufgelistet.
Die Kulturnamen gemäß der Norm RFC 1766 haben das Format "<Sprachcode2>-<Landes-/Regionscode2>". Dabei ist "<Sprachcode2>" ein aus ISO 639-1 abgeleiteter Code aus zwei Kleinbuchstaben, und "<Landes-/Regionsccode2>" ist ein Code aus zwei Großbuchstaben nach ISO 3166. Beispielsweise wird für Englisch (USA) "en-US" verwendet. In Fällen, in denen ein Sprachencode aus zwei Buchstaben nicht zur Verfügung steht, wird der aus ISO 639-2 abgeleitete Code aus drei Buchstaben verwendet. Der aus drei Buchstaben bestehende Code "div" wird beispielsweise für Kulturen verwendet, die die Sprache Dhivehi verwenden. Bestimmte Kulturnamen verfügen über Suffixe, die das verwendete Schriftsystem angeben. Mit "-Cyrl" wird z. B. die kyrillische Schrift und mit "-Latn" die lateinische Schrift angegeben. Die vordefinierten CultureInfo-Namen sind unter dem Thema CultureInfo-Klasse aufgelistet.
Die Kulturen sind i. d. R. in drei Gruppen zusammengefasst: die invariante Kultur, die neutralen Kulturen und die spezifischen Kulturen.
Bei der invarianten Kultur wird keine Kultur berücksichtigt. Sie können die invariante Kultur durch einen Namen mit leerer Zeichenfolge ("") oder durch den zugehörigen Kulturbezeichner 0x007F angeben. InvariantCulture ruft eine Instanz der invarianten Kultur ab. Sie ist der englischen Sprache zugeordnet, aber ohne Bezug auf ein Land oder eine Region. Sie kann in fast allen Methoden im Globalization-Namespace verwendet werden, die eine Kultur erfordern. Wenn eine Sicherheitsentscheidung von einem Zeichenfolgenvergleich oder einer Änderung der Groß-/Kleinschreibung abhängt, stellen Sie mithilfe der InvariantCulture sicher, dass das Verhalten ungeachtet der Kultureinstellungen des Systems konsistent ist. Die invariante Kultur darf jedoch nur von Prozessen verwendet werden, für die kulturunabhängige Ergebnisse erforderlich sind, z. B. von Systemdiensten. Andernfalls werden Ergebnisse erzeugt, die sprachlich falsch oder kulturell ungeeignet sind.
Eine neutrale Kultur ist eine Kultur, die einer Sprache zugeordnet ist, aber keinem Land und keiner Region. Eine spezifische Kultur ist eine Kultur, die einer Sprache und einem Land oder einer Region zugeordnet ist. Beispielsweise ist "fr" eine neutrale Kultur, und "fr-FR" ist eine spezifische Kultur. Beachten Sie, dass es sich bei "zh-CHS" (vereinfachtes Chinesisch) und "zh-CHT" (traditionelles Chinesisch) um neutrale Kulturen handelt.
Hinweise für Aufrufer Dieser Konstruktor akzeptiert ausschließlich spezifizierte Kulturen. Jedoch sind einige neutrale Kulturnamen identisch mit den Landes- bzw. Regionscodes, und in einem entsprechenden Fall löst der Konstruktor bei Verwendung dieser Namen keine ArgumentException aus. Deshalb muss vor dem Erstellen der Klasse RegionInfo mit Kulturnamen des Werts name geprüft werden, dass die Kultur keine InvariantCulture-Eigenschaft ist. Außerdem muss die CultureInfo.IsNeutralCulture-Eigenschaft für diese Kultur den Wert false aufweisen.
Beispiel
Im folgenden Codebeispiel werden zwei auf unterschiedliche Weise erstellte Instanzen von RegionInfo verglichen.
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.
*/
Im folgenden Codebeispiel werden Instanzen der RegionInfo-Klasse mithilfe von Kulturnamen erstellt.
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.
*/
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0
Siehe auch
Referenz
RegionInfo-Klasse
RegionInfo-Member
System.Globalization-Namespace