RegionInfo Konstruktor
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menginisialisasi instans baru dari kelas RegionInfo.
Overload
| Nama | Deskripsi |
|---|---|
| RegionInfo(Int32) |
Menginisialisasi instans RegionInfo baru kelas berdasarkan negara/wilayah yang terkait dengan pengidentifikasi budaya yang ditentukan. |
| RegionInfo(String) |
Menginisialisasi instans RegionInfo baru kelas berdasarkan negara/wilayah atau budaya tertentu, yang ditentukan berdasarkan nama. |
RegionInfo(Int32)
- Sumber:
- RegionInfo.cs
- Sumber:
- RegionInfo.cs
- Sumber:
- RegionInfo.cs
- Sumber:
- RegionInfo.cs
- Sumber:
- RegionInfo.cs
Menginisialisasi instans RegionInfo baru kelas berdasarkan negara/wilayah yang terkait dengan pengidentifikasi budaya yang ditentukan.
public:
RegionInfo(int culture);
public RegionInfo(int culture);
new System.Globalization.RegionInfo : int -> System.Globalization.RegionInfo
Public Sub New (culture As Integer)
Parameter
- culture
- Int32
Pengidentifikasi budaya.
Pengecualian
culture menentukan budaya invarian, kustom, atau netral.
-atau-
Hanya .NET 6+: Mode globalisasi-invariant diaktifkan di lingkungan.
Contoh
Contoh kode berikut membandingkan dua instans RegionInfo yang dibuat secara berbeda.
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.
Keterangan
RegionInfo(String) adalah konstruktor yang direkomendasikan untuk membuat RegionInfo instans objek. RegionInfo(Int32) Tidak seperti konstruktor yang memerlukan pengidentifikasi budaya numerik sebagai parameter, parameternya adalah nama budaya atau kode negara yang lebih dapat dibaca.
Pengidentifikasi budaya dipetakan ke pengidentifikasi lokal Dukungan Bahasa Nasional (NLS) yang sesuai. Untuk informasi selengkapnya, lihat Referensi LCID Windows.
Nilai Name properti objek baru RegionInfo yang dibuat dengan memanggil konstruktor ini adalah kode iso 3166 2 huruf untuk negara/wilayah, bukan bahasa gabungan dan kode negara/wilayah. Misalnya, jika RegionInfo objek dibuat dengan pengidentifikasi budaya 0x0409 untuk budaya Inggris (Amerika Serikat), nilai Name properti adalah "AS". Sebaliknya, jika RegionInfo objek dibuat dengan kode en-US bahasa dan negara/wilayah gabungan untuk budaya Inggris (Amerika Serikat), nilai Name properti adalah "en-US" dalam .NET Framework dan hanya "US" di .NET Core dan .NET 5+.
Lihat juga
Berlaku untuk
RegionInfo(String)
- Sumber:
- RegionInfo.cs
- Sumber:
- RegionInfo.cs
- Sumber:
- RegionInfo.cs
- Sumber:
- RegionInfo.cs
- Sumber:
- RegionInfo.cs
Menginisialisasi instans RegionInfo baru kelas berdasarkan negara/wilayah atau budaya tertentu, yang ditentukan berdasarkan nama.
public:
RegionInfo(System::String ^ name);
public RegionInfo(string name);
new System.Globalization.RegionInfo : string -> System.Globalization.RegionInfo
Public Sub New (name As String)
Parameter
- name
- String
String yang berisi kode dua huruf yang ditentukan dalam ISO 3166 untuk negara/wilayah.
-atau-
String yang berisi nama budaya untuk budaya tertentu, budaya kustom, atau budaya khusus Windows. Jika nama budaya tidak dalam format RFC 4646, aplikasi Anda harus menentukan seluruh nama budaya alih-alih hanya negara/wilayah.
Pengecualian
name adalah null.
name bukan nama negara/wilayah yang valid atau nama budaya tertentu.
-atau-
Hanya .NET 6+: Mode globalisasi-invariant diaktifkan di lingkungan.
Contoh
Contoh kode berikut membandingkan dua instans RegionInfo yang dibuat secara berbeda.
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.
Contoh kode berikut membuat instans penggunaan RegionInfo nama budaya.
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.
Keterangan
Parameter name adalah salah satu kode yang ditentukan untuk negara/wilayah, atau nama budaya khusus, kustom, atau khusus Windows tertentu. Kasus tidak signifikan. Namun, Nameproperti , TwoLetterISORegionName, dan ThreeLetterISORegionName mengembalikan kode atau nama budaya yang ditentukan dalam huruf besar.
Nama yang telah RegionInfo ditentukan sebelumnya tercantum dalam ISO 3166: Kode negara.
Anda harus memberikan nama budaya tertentu daripada hanya nama negara/wilayah dalam name parameter . Misalnya, en-US untuk bahasa Inggris (Amerika Serikat) atau es-US untuk Spanyol (Amerika Serikat) lebih disukai US karena properti seperti NativeName dan CurrencyNativeName mencerminkan bahasa tertentu.
az-Latn-AZ atau az-Cyrl-AZ lebih disukai AZ karena properti seperti NativeName, CurrencyNativeName, dan CurrencySymbol mencerminkan skrip tertentu. Nama budaya yang telah ditentukan sebelumnya tercantum di referensi Windows LCID.
Konstruktor ini melemparkan ArgumentException jika name adalah budaya netral (seperti en untuk bahasa Inggris).
Catatan Bagi Pemanggil
Konstruktor ini hanya menerima budaya atau kode negara/wilayah tertentu. Namun, beberapa nama budaya netral sama dengan kode negara/wilayah. Dalam hal ini, name ditafsirkan sebagai kode negara/wilayah daripada nama budaya netral, dan konstruktor ini tidak melemparkan ArgumentException.