CultureAndRegionInfoBuilder(String, CultureAndRegionModifiers) 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 CultureAndRegionInfoBuilder 類別的新執行個體。
public:
CultureAndRegionInfoBuilder(System::String ^ cultureName, System::Globalization::CultureAndRegionModifiers flags);
public CultureAndRegionInfoBuilder (string cultureName, System.Globalization.CultureAndRegionModifiers flags);
new System.Globalization.CultureAndRegionInfoBuilder : string * System.Globalization.CultureAndRegionModifiers -> System.Globalization.CultureAndRegionInfoBuilder
Public Sub New (cultureName As String, flags As CultureAndRegionModifiers)
參數
- cultureName
- String
文化特性的名稱。
其中一個 CultureAndRegionModifiers 值,指定新的 CultureAndRegionInfoBuilder 物件是否為中性文化特性、是否取代現有的文化特性和國家/地區,或者是新的文化特性。
例外狀況
cultureName
為 null
。
cultureName
為空字串 ("")。
-或-
cultureName
包含除了 "0" 到 "9"、"a" 到 "z"、"A" 到 "Z"、連字號 (-) 或底線 (_) 以外的字元。
-或-
cultureName
包含用來分隔元件的短破折號 (-),但一個或多個 prefix
、language
、region
或 suffix
元件不存在。 也就是說,兩個或更多的短破折號是相鄰的。
-或-
cultureName
的長度超過 84 個字元。
-或-
cultureName
包含用來分隔元件的短破折號,但一個或多個元件的長度超過 8 個字元。
-或-
cultureName
包含前置或後置短破折號 (-) 或底線 (_)。
-或-
cultureName
指定 .NET Framework 文化特性之外的其他排序取代文化特性。 例如,culturenName
是 "de-de_phoneb" (排序出現於德文電話簿內之字串的文化特性),而非 "de-DE" (德文 (德國) 文化特性)。
-或-
flags
包含 CultureAndRegionModifiers 值的無效組合。
-或-
flags
包含 Replacement 或 Neutral,而 cultureName
指定找不到的文化特性。
-或-
flags
包含 Replacement,而 cultureName
指定使用者建立的自訂文化特性,但該文化特性不會取代 .NET Framework 隨附的文化特性。
-或-
flags
包含 Neutral,而 cultureName
指定非中性文化特性的文化特性。
-或-
flags
包含 Neutral,而 cultureName
指定使用者建立的自訂文化特性,且該文化特性會取代 .NET Framework 隨附的特定文化特性。
範例
下列程式代碼範例會建立具有私用使用前置詞的自定義文化特性,然後列出一組其屬性。 第一個屬性會列出文化特性的名稱。
// This example demonstrates a System.Globalization.Culture-
// AndRegionInfoBuilder constructor and some of the properties
// of a custom culture object created with the constructor.
#using <sysglobl.dll>
using namespace System;
using namespace System::Globalization;
int main()
{
CultureAndRegionInfoBuilder^ builder =
gcnew CultureAndRegionInfoBuilder
("x-en-US-sample", CultureAndRegionModifiers::None);
// Display some of the properties
// for the en-US culture.
Console::WriteLine("CultureName:. . . . . . . . . . {0}",
builder->CultureName);
Console::WriteLine("CultureEnglishName: . . . . . . {0}",
builder->CultureEnglishName);
Console::WriteLine("CultureNativeName:. . . . . . . {0}",
builder->CultureNativeName);
Console::WriteLine("GeoId:. . . . . . . . . . . . . {0}",
builder->GeoId);
Console::WriteLine("IsMetric: . . . . . . . . . . . {0}",
builder->IsMetric);
Console::WriteLine("ISOCurrencySymbol:. . . . . . . {0}",
builder->ISOCurrencySymbol);
Console::WriteLine("RegionEnglishName:. . . . . . . {0}",
builder->RegionEnglishName);
Console::WriteLine("RegionName: . . . . . . . . . . {0}",
builder->RegionName);
Console::WriteLine("RegionNativeName: . . . . . . . {0}",
builder->RegionNativeName);
Console::WriteLine("ThreeLetterISOLanguageName: . . {0}",
builder->ThreeLetterISOLanguageName);
Console::WriteLine("ThreeLetterISORegionName: . . . {0}",
builder->ThreeLetterISORegionName);
Console::WriteLine("ThreeLetterWindowsLanguageName: {0}",
builder->ThreeLetterWindowsLanguageName);
Console::WriteLine("ThreeLetterWindowsRegionName: . {0}",
builder->ThreeLetterWindowsRegionName);
Console::WriteLine("TwoLetterISOLanguageName: . . . {0}",
builder->TwoLetterISOLanguageName);
Console::WriteLine("TwoLetterISORegionName: . . . . {0}",
builder->TwoLetterISORegionName);
}
/*
This code example produces the following results:
CultureName:. . . . . . . . . . en-US
CultureEnglishName: . . . . . . English (United States)
CultureNativeName:. . . . . . . English (United States)
GeoId:. . . . . . . . . . . . . 244
IsMetric: . . . . . . . . . . . False
ISOCurrencySymbol:. . . . . . . USD
RegionEnglishName:. . . . . . . United States
RegionName: . . . . . . . . . . US
RegionNativeName: . . . . . . . United States
ThreeLetterISOLanguageName: . . eng
ThreeLetterISORegionName: . . . USA
ThreeLetterWindowsLanguageName: ENU
ThreeLetterWindowsRegionName: . USA
TwoLetterISOLanguageName: . . . en
TwoLetterISORegionName: . . . . US
*/
// This example demonstrates a System.Globalization.Culture-
// AndRegionInfoBuilder constructor and some of the properties
// of the CultureAndRegionInfoBuilder object that is created.
// Compile this example with a reference to sysglobl.dll.
using System;
using System.Globalization;
class Sample
{
public static void Main()
{
// Construct a new, privately used culture that extends the en-US culture
// provided by the .NET Framework. In this sample, the CultureAndRegion-
// Types.Specific parameter creates a minimal CultureAndRegionInfoBuilder
// object that you must populate with culture and region information.
CultureAndRegionInfoBuilder cib = null;
try {
cib = new CultureAndRegionInfoBuilder(
"x-en-US-sample",
CultureAndRegionModifiers.None);
}
catch (ArgumentException ae)
{
Console.WriteLine(ae);
return;
}
// Populate the new CultureAndRegionInfoBuilder object with culture information.
CultureInfo ci = new CultureInfo("en-US");
cib.LoadDataFromCultureInfo(ci);
// Populate the new CultureAndRegionInfoBuilder object with region information.
RegionInfo ri = new RegionInfo("US");
cib.LoadDataFromRegionInfo(ri);
// Display some of the properties for the x-en-US-sample custom culture.
Console.Clear();
Console.WriteLine("CultureName:. . . . . . . . . . {0}", cib.CultureName);
Console.WriteLine("CultureEnglishName: . . . . . . {0}", cib.CultureEnglishName);
Console.WriteLine("CultureNativeName:. . . . . . . {0}", cib.CultureNativeName);
Console.WriteLine("GeoId:. . . . . . . . . . . . . {0}", cib.GeoId);
Console.WriteLine("IsMetric: . . . . . . . . . . . {0}", cib.IsMetric);
Console.WriteLine("ISOCurrencySymbol:. . . . . . . {0}", cib.ISOCurrencySymbol);
Console.WriteLine("RegionEnglishName:. . . . . . . {0}", cib.RegionEnglishName);
Console.WriteLine("RegionName: . . . . . . . . . . {0}", cib.RegionName);
Console.WriteLine("RegionNativeName: . . . . . . . {0}", cib.RegionNativeName);
Console.WriteLine("ThreeLetterISOLanguageName: . . {0}", cib.ThreeLetterISOLanguageName);
Console.WriteLine("ThreeLetterISORegionName: . . . {0}", cib.ThreeLetterISORegionName);
Console.WriteLine("ThreeLetterWindowsLanguageName: {0}", cib.ThreeLetterWindowsLanguageName);
Console.WriteLine("ThreeLetterWindowsRegionName: . {0}", cib.ThreeLetterWindowsRegionName);
Console.WriteLine("TwoLetterISOLanguageName: . . . {0}", cib.TwoLetterISOLanguageName);
Console.WriteLine("TwoLetterISORegionName: . . . . {0}", cib.TwoLetterISORegionName);
}
}
/*
This code example produces the following results:
CultureName:. . . . . . . . . . x-en-US-sample
CultureEnglishName: . . . . . . English
CultureNativeName:. . . . . . . English
GeoId:. . . . . . . . . . . . . 244
IsMetric: . . . . . . . . . . . False
ISOCurrencySymbol:. . . . . . . USD
RegionEnglishName:. . . . . . . United States
RegionName: . . . . . . . . . . US
RegionNativeName: . . . . . . . United States
ThreeLetterISOLanguageName: . . eng
ThreeLetterISORegionName: . . . USA
ThreeLetterWindowsLanguageName: ENU
ThreeLetterWindowsRegionName: . USA
TwoLetterISOLanguageName: . . . en
TwoLetterISORegionName: . . . . US
*/
' This example demonstrates a System.Globalization.Culture-
' AndRegionInfoBuilder constructor and some of the properties
' of the CultureAndRegionInfoBuilder object that is created.
' Compile this example with a reference to sysglobl.dll.
Imports System.Globalization
Class Sample
Public Shared Sub Main()
' Construct a new, privately used culture that extends the en-US culture
' provided by the .NET Framework. In this sample, the CultureAndRegion-
' Types.Specific parameter creates a minimal CultureAndRegionInfoBuilder
' object that you must populate with culture and region information.
Dim cib As CultureAndRegionInfoBuilder = Nothing
Try
cib = New CultureAndRegionInfoBuilder("x-en-US-sample", _
CultureAndRegionModifiers.None)
Catch ae As ArgumentException
Console.WriteLine(ae)
Return
End Try
' Populate the new CultureAndRegionInfoBuilder object with culture information.
Dim ci As New CultureInfo("en-US")
cib.LoadDataFromCultureInfo(ci)
' Populate the new CultureAndRegionInfoBuilder object with region information.
Dim ri As New RegionInfo("US")
cib.LoadDataFromRegionInfo(ri)
' Display some of the properties for the x-en-US-sample custom culture.
Console.Clear()
Console.WriteLine("CultureName:. . . . . . . . . . {0}", cib.CultureName)
Console.WriteLine("CultureEnglishName: . . . . . . {0}", cib.CultureEnglishName)
Console.WriteLine("CultureNativeName:. . . . . . . {0}", cib.CultureNativeName)
Console.WriteLine("GeoId:. . . . . . . . . . . . . {0}", cib.GeoId)
Console.WriteLine("IsMetric: . . . . . . . . . . . {0}", cib.IsMetric)
Console.WriteLine("ISOCurrencySymbol:. . . . . . . {0}", cib.ISOCurrencySymbol)
Console.WriteLine("RegionEnglishName:. . . . . . . {0}", cib.RegionEnglishName)
Console.WriteLine("RegionName: . . . . . . . . . . {0}", cib.RegionName)
Console.WriteLine("RegionNativeName: . . . . . . . {0}", cib.RegionNativeName)
Console.WriteLine("ThreeLetterISOLanguageName: . . {0}", cib.ThreeLetterISOLanguageName)
Console.WriteLine("ThreeLetterISORegionName: . . . {0}", cib.ThreeLetterISORegionName)
Console.WriteLine("ThreeLetterWindowsLanguageName: {0}", cib.ThreeLetterWindowsLanguageName)
Console.WriteLine("ThreeLetterWindowsRegionName: . {0}", cib.ThreeLetterWindowsRegionName)
Console.WriteLine("TwoLetterISOLanguageName: . . . {0}", cib.TwoLetterISOLanguageName)
Console.WriteLine("TwoLetterISORegionName: . . . . {0}", cib.TwoLetterISORegionName)
End Sub
End Class
'
'This code example produces the following results:
'
'CultureName:. . . . . . . . . . x-en-US-sample
'CultureEnglishName: . . . . . . English
'CultureNativeName:. . . . . . . English
'GeoId:. . . . . . . . . . . . . 244
'IsMetric: . . . . . . . . . . . False
'ISOCurrencySymbol:. . . . . . . USD
'RegionEnglishName:. . . . . . . United States
'RegionName: . . . . . . . . . . US
'RegionNativeName: . . . . . . . United States
'ThreeLetterISOLanguageName: . . eng
'ThreeLetterISORegionName: . . . USA
'ThreeLetterWindowsLanguageName: ENU
'ThreeLetterWindowsRegionName: . USA
'TwoLetterISOLanguageName: . . . en
'TwoLetterISORegionName: . . . . US
'
備註
如需此 API 的詳細資訊,請參閱 System.Globalization.CultureAndRegionInfoBuilder 建構函式的補充 API 備註。