gpt4 book ai didi

c# - CultureInfo 名称的常量

转载 作者:IT王子 更新时间:2023-10-29 04:30:36 25 4
gpt4 key购买 nike

C# 系统/全局化命名空间中是否有一组包含有效区域性名称的常量或枚举?

我正在寻找一些东西,这样我就不必输入“en-GB”等。

最佳答案

是的,有,GetCultures :

System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.SpecificCultures)

这会返回一个 CultureInfo 对象数组,因此如果您想要字符串名称,您可以使用如下内容:

IEnumerable<CultureInfo> cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
string[] names = cultures.Select(c => c.Name).ToArray();

注意“文化类型”枚举(来自 MSDN 链接)。我想最有用的是 NeutralCulturesSpecificCultures

  • NeutralCultures Cultures that are associated with a language but are not specific to a country/region. The names of .NET Framework cultures consist of the lowercase two-letter code derived from ISO 639-1. For example: "en" (English) is a neutral culture. Custom cultures can have any user-specified name, not just a two-letter code. The invariant culture is included in the array of cultures returned by the CultureInfo.GetCultures method that specifies this value.
  • SpecificCultures Cultures that are specific to a country/region. The names of these cultures follow RFC 4646 (Windows Vista and later). The format is "-", where is a lowercase two-letter code derived from ISO 639-1 and is an uppercase two-letter code derived from ISO 3166. For example, "en-US" for English (United States) is a specific culture. Custom cultures can have any user-specified name, not just a standard-compliant name.
  • InstalledWin32Cultures All cultures that are installed in the Windows operating system. Note that not all cultures supported by the .NET Framework are installed in the operating system.
  • AllCultures All cultures that ship with the .NET Framework, including neutral and specific cultures, cultures installed in the Windows operating system, and custom cultures created by the user.
  • UserCustomCulture Custom cultures created by the user.
  • ReplacementCultures Custom cultures created by the user that replace cultures shipped with the .NET Framework.

关于c# - CultureInfo 名称的常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12613211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com