CultureInfo.CreateSpecificCulture(String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建表示与指定名称关联的特定区域性的 CultureInfo。
public:
static System::Globalization::CultureInfo ^ CreateSpecificCulture(System::String ^ name);
public static System.Globalization.CultureInfo CreateSpecificCulture (string name);
static member CreateSpecificCulture : string -> System.Globalization.CultureInfo
Public Shared Function CreateSpecificCulture (name As String) As CultureInfo
参数
- name
- String
预定义的 CultureInfo 名称或现有 CultureInfo 的对象。
name
不区分大小写。
返回
一个表示以下内容的 CultureInfo 对象:
如果 name
为空字符串(“”),则为固定区域性。
或
与 name
关联的特定区域性,如果 name
是非特定区域性。
或
由 name
指定的区域性,如果 name
已经是特定区域性。
例外
name
为 null。
示例
下面的示例从 GetCultures 方法中检索表示非特定区域性的 对象的数组CultureInfo,并对数组进行排序。 当它循环访问数组中的元素时,它将每个非特定区域性的名称传递给 CreateSpecificCulture 方法,并显示该方法返回的特定区域性的名称。
注意
该示例使用 zh-CHS
和 zh-CHT
区域性名称。 但是,面向 Windows Vista 及更高版本的应用程序应使用 zh-Hans
而不是 zh-CHS
和 zh-Hant
而不是 zh-CHT。
zh-Hans
和 zh-Hant
表示当前标准,除非有理由使用旧名称,否则应使用 。
另请注意,本示例的结果在安装台湾 Windows 时可能有所不同,其中中国 (传统) 中性文化 (zh、zh-CHT 或 zh-Hant) 将返回 zh-TW。
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
public class Example
{
public static void Main()
{
// Display the header.
Console.WriteLine("{0,-53}{1}", "CULTURE", "SPECIFIC CULTURE");
// Get each neutral culture in the .NET Framework.
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.NeutralCultures);
// Sort the returned array by name.
Array.Sort<CultureInfo>(cultures, new NamePropertyComparer<CultureInfo>());
// Determine the specific culture associated with each neutral culture.
foreach (var culture in cultures)
{
Console.Write("{0,-12} {1,-40}", culture.Name, culture.EnglishName);
try {
Console.WriteLine("{0}", CultureInfo.CreateSpecificCulture(culture.Name).Name);
}
catch (ArgumentException) {
Console.WriteLine("(no associated specific culture)");
}
}
}
}
public class NamePropertyComparer<T> : IComparer<T>
{
public int Compare(T x, T y)
{
if (x == null)
if (y == null)
return 0;
else
return -1;
PropertyInfo pX = x.GetType().GetProperty("Name");
PropertyInfo pY = y.GetType().GetProperty("Name");
return String.Compare((string) pX.GetValue(x, null), (string) pY.GetValue(y, null));
}
}
// The example displays the following output on a Windows system. This output has been cropped for brevity.
// CULTURE SPECIFIC CULTURE
// Invariant Language (Invariant Country)
// aa Afar aa-ET
// af Afrikaans af-ZA
// agq Aghem agq-CM
// ak Akan ak-GH
// am Amharic am-ET
// ar Arabic ar-SA
// arn Mapudungun arn-CL
// as Assamese as-IN
// asa Asu asa-TZ
// ast Asturian ast-ES
// az Azerbaijani az-Latn-AZ
// az-Cyrl Azerbaijani (Cyrillic) az-Cyrl-AZ
// az-Latn Azerbaijani (Latin) az-Latn-AZ
// ba Bashkir ba-RU
// bas Basaa bas-CM
// be Belarusian be-BY
// bem Bemba bem-ZM
// bez Bena bez-TZ
// bg Bulgarian bg-BG
// bin Edo bin-NG
// bm Bamanankan bm-Latn-ML
// bm-Latn Bamanankan (Latin) bm-Latn-ML
// bn Bangla bn-BD
// bo Tibetan bo-CN
// br Breton br-FR
// brx Bodo brx-IN
// bs Bosnian bs-Latn-BA
// bs-Cyrl Bosnian (Cyrillic) bs-Cyrl-BA
// bs-Latn Bosnian (Latin) bs-Latn-BA
// byn Blin byn-ER
// ca Catalan ca-ES
// ce Chechen ce-RU
// cgg Chiga cgg-UG
// chr Cherokee chr-Cher-US
// chr-Cher Cherokee chr-Cher-US
// co Corsican co-FR
// cs Czech cs-CZ
// cu Church Slavic cu-RU
// cy Welsh cy-GB
// da Danish da-DK
// dav Taita dav-KE
// de German de-DE
// dje Zarma dje-NE
// dsb Lower Sorbian dsb-DE
// dua Duala dua-CM
// dv Divehi dv-MV
// ...
// ta Tamil ta-IN
// te Telugu te-IN
// teo Teso teo-UG
// tg Tajik tg-Cyrl-TJ
// tg-Cyrl Tajik (Cyrillic) tg-Cyrl-TJ
// th Thai th-TH
// ti Tigrinya ti-ER
// tig Tigre tig-ER
// tk Turkmen tk-TM
// tn Setswana tn-ZA
// to Tongan to-TO
// tr Turkish tr-TR
// ts Tsonga ts-ZA
// tt Tatar tt-RU
// twq Tasawaq twq-NE
// tzm Central Atlas Tamazight tzm-Latn-DZ
// tzm-Arab Central Atlas Tamazight (Arabic) tzm-Arab-MA
// tzm-Latn Central Atlas Tamazight (Latin) tzm-Latn-DZ
// tzm-Tfng Central Atlas Tamazight (Tifinagh) tzm-Tfng-MA
// ug Uyghur ug-CN
// uk Ukrainian uk-UA
// ur Urdu ur-PK
// uz Uzbek uz-Latn-UZ
// uz-Arab Uzbek (Perso-Arabic) uz-Arab-AF
// uz-Cyrl Uzbek (Cyrillic) uz-Cyrl-UZ
// uz-Latn Uzbek (Latin) uz-Latn-UZ
// vai Vai vai-Vaii-LR
// vai-Latn Vai (Latin) vai-Latn-LR
// vai-Vaii Vai (Vai) vai-Vaii-LR
// ve Venda ve-ZA
// vi Vietnamese vi-VN
// vo Volapük vo-001
// vun Vunjo vun-TZ
// wae Walser wae-CH
// wal Wolaytta wal-ET
// wo Wolof wo-SN
// xh isiXhosa xh-ZA
// xog Soga xog-UG
// yav Yangben yav-CM
// yi Yiddish yi-001
// yo Yoruba yo-NG
// zgh Standard Moroccan Tamazight zgh-Tfng-MA
// zgh-Tfng Standard Moroccan Tamazight (Tifinagh) zgh-Tfng-MA
// zh Chinese zh-CN
// zh-CHS Chinese (Simplified) Legacy zh-CN
// zh-CHT Chinese (Traditional) Legacy zh-HK
// zh-Hans Chinese (Simplified) zh-CN
// zh-Hant Chinese (Traditional) zh-HK
// zu isiZulu zu-ZA
// The example displays output like the following on a Unix-based system. The output has been cropped for brevity.
// CULTURE SPECIFIC CULTURE
// Invariant Language (Invariant Country)
// af Afrikaans af-ZA
// agq Aghem agq-CM
// ak Akan ak-GH
// am Amharic am-ET
// ar Arabic ar-SA
// as Assamese as-IN
// asa Asu asa-TZ
// ast Asturian ast-ES
// az Azerbaijani az-Latn-AZ
// az-Cyrl Azerbaijani az-Cyrl-AZ
// az-Latn Azerbaijani az-Latn-AZ
// bas Basaa bas-CM
// be Belarusian be-BY
// bem Bemba bem-ZM
// bez Bena bez-TZ
// bg Bulgarian bg-BG
// bm Bambara bm-Latn-ML
// bn Bangla bn-BD
// bo Tibetan bo-CN
// br Breton br-FR
// brx Bodo brx-IN
// bs Bosnian bs-Latn-BA
// bs-Cyrl Bosnian bs-Cyrl-BA
// bs-Latn Bosnian bs-Latn-BA
// ca Catalan ca-ES
// ccp Chakma
// ce Chechen ce-RU
// cgg Chiga cgg-UG
// chr Cherokee chr-Cher-US
// ckb Central Kurdish
// cs Czech cs-CZ
// cy Welsh cy-GB
// da Danish da-DK
// dav Taita dav-KE
// de German de-DE
// dje Zarma dje-NE
// dsb Lower Sorbian dsb-DE
// dua Duala dua-CM
// ...
// ta Tamil ta-IN
// te Telugu te-IN
// teo Teso teo-UG
// tg Tajik tg-Cyrl-TJ
// th Thai th-TH
// ti Tigrinya ti-ER
// to Tongan to-TO
// tr Turkish tr-TR
// tt Tatar tt-RU
// twq Tasawaq twq-NE
// tzm Central Atlas Tamazight tzm-Latn-DZ
// ug Uyghur ug-CN
// uk Ukrainian uk-UA
// ur Urdu ur-PK
// uz Uzbek uz-Latn-UZ
// uz-Arab Uzbek uz-Arab-AF
// uz-Cyrl Uzbek uz-Cyrl-UZ
// uz-Latn Uzbek uz-Latn-UZ
// vai Vai vai-Vaii-LR
// vai-Latn Vai vai-Latn-LR
// vai-Vaii Vai vai-Vaii-LR
// vi Vietnamese vi-VN
// vun Vunjo vun-TZ
// wae Walser wae-CH
// wo Wolof wo-SN
// xog Soga xog-UG
// yav Yangben yav-CM
// yi Yiddish yi-001
// yo Yoruba yo-NG
// yue Cantonese yue-HK
// yue-Hans Cantonese
// yue-Hant Cantonese
// zgh Standard Moroccan Tamazight zgh-Tfng-MA
// zh Chinese zh-CN
// zh-Hans Chinese zh-CN
// zh-Hant Chinese zh-HK
// zu Zulu zu-ZA
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Reflection
Public Class Example
Public Shared Sub Main()
' Display the header.
Console.WriteLine("{0,-53}{1}", "CULTURE", "SPECIFIC CULTURE")
' Get each neutral culture in the .NET Framework.
Dim cultures() As CultureInfo = CultureInfo.GetCultures(CultureTypes.NeutralCultures)
' Sort the returned array by name.
Array.Sort(Of CultureInfo)(cultures, New NamePropertyComparer(Of CultureInfo)())
' Determine the specific culture associated with each neutral culture.
For Each culture As CultureInfo In cultures
Console.Write("{0,-12} {1,-40}", culture.Name, culture.EnglishName)
Try
Console.WriteLine("{0}", CultureInfo.CreateSpecificCulture(culture.Name).Name)
Catch e As ArgumentException
Console.WriteLine("(no associated specific culture)")
End Try
Next
End Sub
End Class
Public Class NamePropertyComparer(Of T) : Implements IComparer(Of T)
Public Function Compare(x As T, y As T) As Integer _
Implements IComparer(Of T).Compare
If x Is Nothing Then
If y Is Nothing Then
Return 0
Else
Return -1
End If
End If
Dim pX As PropertyInfo = x.GetType().GetProperty("Name")
Dim pY As PropertyInfo = y.GetType().GetProperty("Name")
Return String.Compare(CStr(pX.GetValue(x, Nothing)), CStr(pY.GetValue(y, Nothing)))
End Function
End Class
' The example displays the following output on a Windows system. This output has been cropped for brevity.
' CULTURE SPECIFIC CULTURE
Invariant Language (Invariant Country)
' aa Afar aa-ET
' af Afrikaans af-ZA
' agq Aghem agq-CM
' ak Akan ak-GH
' am Amharic am-ET
' ar Arabic ar-SA
' arn Mapudungun arn-CL
' as Assamese as-IN
' asa Asu asa-TZ
' ast Asturian ast-ES
' az Azerbaijani az-Latn-AZ
' az-Cyrl Azerbaijani (Cyrillic) az-Cyrl-AZ
' az-Latn Azerbaijani (Latin) az-Latn-AZ
' ba Bashkir ba-RU
' bas Basaa bas-CM
' be Belarusian be-BY
' bem Bemba bem-ZM
' bez Bena bez-TZ
' bg Bulgarian bg-BG
' bin Edo bin-NG
' bm Bamanankan bm-Latn-ML
' bm-Latn Bamanankan (Latin) bm-Latn-ML
' bn Bangla bn-BD
' bo Tibetan bo-CN
' br Breton br-FR
' brx Bodo brx-IN
' bs Bosnian bs-Latn-BA
' bs-Cyrl Bosnian (Cyrillic) bs-Cyrl-BA
' bs-Latn Bosnian (Latin) bs-Latn-BA
' byn Blin byn-ER
' ca Catalan ca-ES
' ce Chechen ce-RU
' cgg Chiga cgg-UG
' chr Cherokee chr-Cher-US
' chr-Cher Cherokee chr-Cher-US
' co Corsican co-FR
' cs Czech cs-CZ
' cu Church Slavic cu-RU
' cy Welsh cy-GB
' da Danish da-DK
' dav Taita dav-KE
' de German de-DE
' dje Zarma dje-NE
' dsb Lower Sorbian dsb-DE
' dua Duala dua-CM
' dv Divehi dv-MV
' ...
' ta Tamil ta-IN
' te Telugu te-IN
' teo Teso teo-UG
' tg Tajik tg-Cyrl-TJ
' tg-Cyrl Tajik (Cyrillic) tg-Cyrl-TJ
' th Thai th-TH
' ti Tigrinya ti-ER
' tig Tigre tig-ER
' tk Turkmen tk-TM
' tn Setswana tn-ZA
' to Tongan to-TO
' tr Turkish tr-TR
' ts Tsonga ts-ZA
' tt Tatar tt-RU
' twq Tasawaq twq-NE
' tzm Central Atlas Tamazight tzm-Latn-DZ
' tzm-Arab Central Atlas Tamazight (Arabic) tzm-Arab-MA
' tzm-Latn Central Atlas Tamazight (Latin) tzm-Latn-DZ
' tzm-Tfng Central Atlas Tamazight (Tifinagh) tzm-Tfng-MA
' ug Uyghur ug-CN
' uk Ukrainian uk-UA
' ur Urdu ur-PK
' uz Uzbek uz-Latn-UZ
' uz-Arab Uzbek (Perso-Arabic) uz-Arab-AF
' uz-Cyrl Uzbek (Cyrillic) uz-Cyrl-UZ
' uz-Latn Uzbek (Latin) uz-Latn-UZ
' vai Vai vai-Vaii-LR
' vai-Latn Vai (Latin) vai-Latn-LR
' vai-Vaii Vai (Vai) vai-Vaii-LR
' ve Venda ve-ZA
' vi Vietnamese vi-VN
' vo Volapük vo-001
' vun Vunjo vun-TZ
' wae Walser wae-CH
' wal Wolaytta wal-ET
' wo Wolof wo-SN
' xh isiXhosa xh-ZA
' xog Soga xog-UG
' yav Yangben yav-CM
' yi Yiddish yi-001
' yo Yoruba yo-NG
' zgh Standard Moroccan Tamazight zgh-Tfng-MA
' zgh-Tfng Standard Moroccan Tamazight (Tifinagh) zgh-Tfng-MA
' zh Chinese zh-CN
' zh-CHS Chinese (Simplified) Legacy zh-CN
' zh-CHT Chinese (Traditional) Legacy zh-HK
' zh-Hans Chinese (Simplified) zh-CN
' zh-Hant Chinese (Traditional) zh-HK
' zu isiZulu zu-ZA
' The example displays output like the following on a Unix-based system. The output has been cropped for brevity.
CULTURE SPECIFIC CULTURE
' Invariant Language (Invariant Country)
' af Afrikaans af-ZA
' agq Aghem agq-CM
' ak Akan ak-GH
' am Amharic am-ET
' ar Arabic ar-SA
' as Assamese as-IN
' asa Asu asa-TZ
' ast Asturian ast-ES
' az Azerbaijani az-Latn-AZ
' az-Cyrl Azerbaijani az-Cyrl-AZ
' az-Latn Azerbaijani az-Latn-AZ
' bas Basaa bas-CM
' be Belarusian be-BY
' bem Bemba bem-ZM
' bez Bena bez-TZ
' bg Bulgarian bg-BG
' bm Bambara bm-Latn-ML
' bn Bangla bn-BD
' bo Tibetan bo-CN
' br Breton br-FR
' brx Bodo brx-IN
' bs Bosnian bs-Latn-BA
' bs-Cyrl Bosnian bs-Cyrl-BA
' bs-Latn Bosnian bs-Latn-BA
' ca Catalan ca-ES
' ccp Chakma
' ce Chechen ce-RU
' cgg Chiga cgg-UG
' chr Cherokee chr-Cher-US
' ckb Central Kurdish
' cs Czech cs-CZ
' cy Welsh cy-GB
' da Danish da-DK
' dav Taita dav-KE
' de German de-DE
' dje Zarma dje-NE
' dsb Lower Sorbian dsb-DE
' dua Duala dua-CM
' ...
' ta Tamil ta-IN
' te Telugu te-IN
' teo Teso teo-UG
' tg Tajik tg-Cyrl-TJ
' th Thai th-TH
' ti Tigrinya ti-ER
' to Tongan to-TO
' tr Turkish tr-TR
' tt Tatar tt-RU
' twq Tasawaq twq-NE
' tzm Central Atlas Tamazight tzm-Latn-DZ
' ug Uyghur ug-CN
' uk Ukrainian uk-UA
' ur Urdu ur-PK
' uz Uzbek uz-Latn-UZ
' uz-Arab Uzbek uz-Arab-AF
' uz-Cyrl Uzbek uz-Cyrl-UZ
' uz-Latn Uzbek uz-Latn-UZ
' vai Vai vai-Vaii-LR
' vai-Latn Vai vai-Latn-LR
' vai-Vaii Vai vai-Vaii-LR
' vi Vietnamese vi-VN
' vun Vunjo vun-TZ
' wae Walser wae-CH
' wo Wolof wo-SN
' xog Soga xog-UG
' yav Yangben yav-CM
' yi Yiddish yi-001
' yo Yoruba yo-NG
' yue Cantonese yue-HK
' yue-Hans Cantonese
' yue-Hant Cantonese
' zgh Standard Moroccan Tamazight zgh-Tfng-MA
' zh Chinese zh-CN
' zh-Hans Chinese zh-CN
' zh-Hant Chinese zh-HK
' zu Zulu zu-ZA
注解
方法 CreateSpecificCulture 包装对构造函数的 CultureInfo(String) 调用。
注意
有关 Windows 系统上预定义区域性名称的列表,请参阅 Windows 支持的语言/区域名称列表中的“语言标记”列。 列名遵循 BCP 47 定义的标准。 此外,从 Windows 10 开始, name
可以是任何有效的 BCP-47 语言标记。
区域性分为三组:固定区域性、非特定区域性和特定区域性。 有关详细信息,请参阅 类的说明 CultureInfo 。
如果此方法返回的特定区域性的区域性标识符与当前 Windows 区域性的区域性标识符匹配,则此方法将创建一个 CultureInfo 使用 Windows 区域性替代的对象。 替代包括属性返回DateTimeFormat的 DateTimeFormatInfo 对象的属性和 NumberFormatInfo 属性返回NumberFormat的对象的用户设置。 若要实例化CultureInfo具有默认区域性设置而不是用户替代的对象,请使用 参数的 false
useUserOverride
值调用CultureInfo(String, Boolean)构造函数。
CreateSpecificCulture尽管方法名称包含术语“Specific”,但请记住,区域性数据可以在版本之间更改,或者由于自定义区域性或用户替代。 使用固定区域性或二进制或固定格式保存数据。
调用方说明
如果 name
不是有效的区域性名称,ArgumentException则 .NET Framework 3.5 及更早版本会引发 。 从 .NET Framework 4 开始,此方法引发 CultureNotFoundException。
在 .NET 6 及更高版本上, CultureNotFoundException 如果应用在启用了全球化固定模式的环境中运行(例如,某些 Docker 容器)和指定固定区域性以外的区域性,则会引发 。