CultureInfo 类

    技术2022-05-11  109

    CultureInfo 类 

    提供有关特定区域性的信息(如区域性的名称、书写系统和使用的日历)以及如何设置日期和排序字符串的格式。

    命名空间:System.Globalization程序集:mscorlib(在 mscorlib.dll 中)

    <script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl028e3402f,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl02img,"; </script> 语法 Visual Basic(声明) <SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public Class CultureInfo Implements ICloneable, IFormatProvider Visual Basic(用法) Dim instance As CultureInfo C# [SerializableAttribute] [ComVisibleAttribute(true)] public class CultureInfo : ICloneable, IFormatProvider C++ [SerializableAttribute] [ComVisibleAttribute(true)] public ref class CultureInfo : ICloneable, IFormatProvider J# /** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ public class CultureInfo implements ICloneable, IFormatProvider JScript SerializableAttribute ComVisibleAttribute(true) public class CultureInfo implements ICloneable, IFormatProvider <script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl0940cb78f,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl09img,"; </script> 备注

    CultureInfo 类保存区域性特定的信息,如关联的语言、子语言、国家/地区、日历和区域性约定。此类还提供对 DateTimeFormatInfo、NumberFormatInfo、CompareInfo 和 TextInfo 的区域性特定实例的访问。这些对象包含区域性特定操作(如大小写、格式化日期和数字以及比较字符串)所需的信息。

    String 类间接地使用此类来获取有关默认区域性的信息。

    区域性名称和标识符

    区域性名称遵循 RFC 1766 标准,格式为“<languagecode2>-<country/regioncode2>”,其中 <languagecode2> 是从 ISO 639-1 派生的由两个小写字母构成的代码,<country/regioncode2> 是从 ISO 3166 派生的由两个大写字母构成的代码。例如,美国英语为“en-US”。在双字母语言代码不可用的情况中,将使用从 ISO 639-2 派生的三字母代码;例如,三字母代码“div”用于使用 Dhivehi 语言的区域。某些区域性名称带有指定书写符号的后缀;例如“-Cyrl”指定西里尔语书写符号,“-Latn”指定拉丁语书写符号。

    System.Globalization 命名空间中的此类和其他类接受并使用下列预定义的区域性名称和标识符。

     

    区域性名称

    区域性标识符

    语言-国家/地区

    ""(空字符串)

    0x007F

    固定区域性

    af

    0x0036

    南非荷兰语

    af-ZA

    0x0436

    南非荷兰语 - 南非

    sq

    0x001C

    阿尔巴尼亚语

    sq-AL

    0x041C

    阿尔巴尼亚语 - 阿尔巴尼亚

    ar

    0x0001

    阿拉伯语

    ar-DZ

    0x1401

    阿拉伯语 - 阿尔及利亚

    ar-BH

    0x3C01

    阿拉伯语 - 巴林

    ar-EG

    0x0C01

    阿拉伯语 - 埃及

    ar-IQ

    0x0801

    阿拉伯语 - 伊拉克

    ar-JO

    0x2C01

    阿拉伯语 - 约旦

    ar-KW

    0x3401

    阿拉伯语 - 科威特

    ar-LB

    0x3001

    阿拉伯语 - 黎巴嫩

    ar-LY

    0x1001

    阿拉伯语 - 利比亚

    ar-MA

    0x1801

    阿拉伯语 - 摩洛哥

    ar-OM

    0x2001

    阿拉伯语 - 阿曼

    ar-QA

    0x4001

    阿拉伯语 - 卡塔尔

    ar-SA

    0x0401

    阿拉伯语 - 沙特阿拉伯

    ar-SY

    0x2801

    阿拉伯语 - 叙利亚

    ar-TN

    0x1C01

    阿拉伯语 - 突尼斯

    ar-AE

    0x3801

    阿拉伯语 - 阿拉伯联合酋长国

    ar-YE

    0x2401

    阿拉伯语 - 也门

    hy

    0x002B

    亚美尼亚语

    hy-AM

    0x042B

    亚美尼亚语 - 亚美尼亚

    az

    0x002C

    阿泽里语

    az-AZ-Cyrl

    0x082C

    阿泽里语(西里尔语)- 阿塞拜疆

    az-AZ-Latn

    0x042C

    阿泽里语(拉丁)- 阿塞拜疆

    eu

    0x002D

    巴斯克语

    eu-ES

    0x042D

    巴斯克语 - 巴斯克地区

    be

    0x0023

    白俄罗斯语

    be-BY

    0x0423

    白俄罗斯语 - 白俄罗斯

    bg

    0x0002

    保加利亚语

    bg-BG

    0x0402

    保加利亚语 - 保加利亚

    ca

    0x0003

    加泰罗尼亚语

    ca-ES

    0x0403

    加泰罗尼亚语 - 加泰罗尼亚地区

    zh-HK

    0x0C04

    中文 - 香港特别行政区

    zh-MO

    0x1404

    中文 - 澳门特别行政区

    zh-CN

    0x0804

    中文 - 中国

    zh-CHS

    0x0004

    中文(简体)

    zh-SG

    0x1004

    中文 - 新加坡

    zh-TW

    0x0404

    中文 - 台湾

    zh-CHT

    0x7C04

    中文(繁体)

    hr

    0x001A

    克罗地亚语

    hr-HR

    0x041A

    克罗地亚语 - 克罗地亚

    cs

    0x0005

    捷克语

    cs-CZ

    0x0405

    捷克语 - 捷克共和国

    da

    0x0006

    丹麦语

    da-DK

    0x0406

    丹麦语 - 丹麦

    div

    0x0065

    马尔代夫语

    div-MV

    0x0465

    马尔代夫语 - 马尔代夫

    nl

    0x0013

    荷兰语

    nl-BE

    0x0813

    荷兰语 - 比利时

    nl-NL

    0x0413

    荷兰语 - 荷兰

    en

    0x0009

    英语

    en-AU

    0x0C09

    英语 - 澳大利亚

    en-BZ

    0x2809

    英语 - 伯利兹

    en-CA

    0x1009

    英语 - 加拿大

    en-CB

    0x2409

    英语 - 加勒比

    en-IE

    0x1809

    英语 - 爱尔兰

    en-JM

    0x2009

    英语 - 牙买加

    en-NZ

    0x1409

    英语 - 新西兰

    en-PH

    0x3409

    英语 - 菲律宾

    en-ZA

    0x1C09

    英语 - 南非

    en-TT

    0x2C09

    英语 - 特立尼达和多巴哥

    en-GB

    0x0809

    英语 - 英国

    en-US

    0x0409

    英语 - 美国

    en-ZW

    0x3009

    英语 - 津巴布韦

    et

    0x0025

    爱沙尼亚语

    et-EE

    0x0425

    爱沙尼亚语 - 爱沙尼亚

    fo

    0x0038

    法罗语

    fo-FO

    0x0438

    法罗语 - 法罗群岛

    fa

    0x0029

    波斯语

    fa-IR

    0x0429

    波斯语 - 伊朗

    fi

    0x000B

    芬兰语

    fi-FI

    0x040B

    芬兰语 - 芬兰

    fr

    0x000C

    法语

    fr-BE

    0x080C

    法语 - 比利时

    fr-CA

    0x0C0C

    法语 - 加拿大

    fr-FR

    0x040C

    法语 - 法国

    fr-LU

    0x140C

    法语 - 卢森堡

    fr-MC

    0x180C

    法语 - 摩纳哥

    fr-CH

    0x100C

    法语 - 瑞士

    gl

    0x0056

    加利西亚语

    gl-ES

    0x0456

    加利西亚语 - 加利西亚地区

    ka

    0x0037

    格鲁吉亚语

    ka-GE

    0x0437

    格鲁吉亚语 - 格鲁吉亚

    de

    0x0007

    德语

    de-AT

    0x0C07

    德语 - 奥地利

    de-DE

    0x0407

    德语 - 德国

    de-LI

    0x1407

    德语 - 列支敦士登

    de-LU

    0x1007

    德语 - 卢森堡

    de-CH

    0x0807

    德语 - 瑞士

    el

    0x0008

    希腊语

    el-GR

    0x0408

    希腊语 - 希腊

    gu

    0x0047

    古吉拉特语

    gu-IN

    0x0447

    古吉拉特语 - 印度

    he

    0x000D

    希伯来语

    he-IL

    0x040D

    希伯来语 - 以色列

    hi

    0x0039

    印地语

    hi-IN

    0x0439

    印地语 - 印度

    hu

    0x000E

    匈牙利语

    hu-HU

    0x040E

    匈牙利语 - 匈牙利

    is

    0x000F

    冰岛语

    is-IS

    0x040F

    冰岛语 - 冰岛

    id

    0x0021

    印度尼西亚语

    id-ID

    0x0421

    印度尼西亚语 - 印度尼西亚

    it

    0x0010

    意大利语

    it-IT

    0x0410

    意大利语 - 意大利

    it-CH

    0x0810

    意大利语 - 瑞士

    ja

    0x0011

    日语

    ja-JP

    0x0411

    日语 - 日本

    kn

    0x004B

    卡纳达语

    kn-IN

    0x044B

    卡纳达语 - 印度

    kk

    0x003F

    哈萨克语

    kk-KZ

    0x043F

    哈萨克语 - 哈萨克斯坦

    kok

    0x0057

    贡根语

    kok-IN

    0x0457

    贡根语 - 印度

    ko

    0x0012

    朝鲜语

    ko-KR

    0x0412

    朝鲜语 - 韩国

    ky

    0x0040

    吉尔吉斯语

    ky-KG

    0x0440

    吉尔吉斯语 - 吉尔吉斯坦

    lv

    0x0026

    拉脱维亚语

    lv-LV

    0x0426

    拉脱维亚语 - 拉脱维亚

    lt

    0x0027

    立陶宛语

    lt-LT

    0x0427

    立陶宛语 - 立陶宛

    mk

    0x002F

    马其顿语

    mk-MK

    0x042F

    马其顿语 - 前南斯拉夫联盟马其顿共和国

    ms

    0x003E

    马来语

    ms-BN

    0x083E

    马来语 - 文莱

    ms-MY

    0x043E

    马来语 - 马来西亚

    mr

    0x004E

    马拉地语

    mr-IN

    0x044E

    马拉地语 - 印度

    mn

    0x0050

    蒙古语

    mn-MN

    0x0450

    蒙古语 - 蒙古

    no

    0x0014

    挪威语

    nb-NO

    0x0414

    挪威语(伯克梅尔)- 挪威

    nn-NO

    0x0814

    挪威语(尼诺斯克)- 挪威

    pl

    0x0015

    波兰语

    pl-PL

    0x0415

    波兰语 - 波兰

    pt

    0x0016

    葡萄牙语

    pt-BR

    0x0416

    葡萄牙语 - 巴西

    pt-PT

    0x0816

    葡萄牙语 - 葡萄牙

    pa

    0x0046

    旁遮普语

    pa-IN

    0x0446

    旁遮普语 - 印度

    ro

    0x0018

    罗马尼亚语

    ro-RO

    0x0418

    罗马尼亚语 - 罗马尼亚

    ru

    0x0019

    俄语

    ru-RU

    0x0419

    俄语 - 俄罗斯

    sa

    0x004F

    梵语

    sa-IN

    0x044F

    梵语 - 印度

    sr-SP-Cyrl

    0x0C1A

    塞尔维亚语(西里尔语)- 塞尔维亚

    sr-SP-Latn

    0x081A

    塞尔维亚语(拉丁)- 塞尔维亚

    sk

    0x001B

    斯洛伐克语

    sk-SK

    0x041B

    斯洛伐克语 - 斯洛伐克

    sl

    0x0024

    斯洛文尼亚语

    sl-SI

    0x0424

    斯洛文尼亚语 - 斯洛文尼亚

    es

    0x000A

    西班牙语

    es-AR

    0x2C0A

    西班牙语 - 阿根廷

    es-BO

    0x400A

    西班牙语 - 玻利维亚

    es-CL

    0x340A

    西班牙语 - 智利

    es-CO

    0x240A

    西班牙语 - 哥伦比亚

    es-CR

    0x140A

    西班牙语 - 哥斯达黎加

    es-DO

    0x1C0A

    西班牙语 - 多米尼加共和国

    es-EC

    0x300A

    西班牙语 - 厄瓜多尔

    es-SV

    0x440A

    西班牙语 - 萨尔瓦多

    es-GT

    0x100A

    西班牙语 - 危地马拉

    es-HN

    0x480A

    西班牙语 - 洪都拉斯

    es-MX

    0x080A

    西班牙语 - 墨西哥

    es-NI

    0x4C0A

    西班牙语 - 尼加拉瓜

    es-PA

    0x180A

    西班牙语 - 巴拿马

    es-PY

    0x3C0A

    西班牙语 - 巴拉圭

    es-PE

    0x280A

    西班牙 - 秘鲁

    es-PR

    0x500A

    西班牙语 - 波多黎各

    es-ES

    0x0C0A

    西班牙语 - 西班牙

    es-UY

    0x380A

    西班牙语 - 乌拉圭

    es-VE

    0x200A

    西班牙语 - 委内瑞拉

    sw

    0x0041

    斯瓦希里语

    sw-KE

    0x0441

    斯瓦希里语 - 肯尼亚

    sv

    0x001D

    瑞典语

    sv-FI

    0x081D

    瑞典语 - 芬兰

    sv-SE

    0x041D

    瑞典语 - 瑞典

    syr

    0x005A

    叙利亚语

    syr-SY

    0x045A

    叙利亚语 - 叙利亚

    ta

    0x0049

    泰米尔语

    ta-IN

    0x0449

    泰米尔语 - 印度

    tt

    0x0044

    鞑靼语

    tt-RU

    0x0444

    鞑靼语 - 俄罗斯

    te

    0x004A

    泰卢固语

    te-IN

    0x044A

    泰卢固语 - 印度

    th

    0x001E

    泰语

    th-TH

    0x041E

    泰语 - 泰国

    tr

    0x001F

    土耳其语

    tr-TR

    0x041F

    土耳其语 - 土耳其

    uk

    0x0022

    乌克兰语

    uk-UA

    0x0422

    乌克兰语 - 乌克兰

    ur

    0x0020

    乌尔都语

    ur-PK

    0x0420

    乌尔都语 - 巴基斯坦

    uz

    0x0043

    乌兹别克语

    uz-UZ-Cyrl

    0x0843

    乌兹别克语(西里尔语)- 乌兹别克斯坦

    uz-UZ-Latn

    0x0443

    乌兹别克语(拉丁)- 乌兹别克斯坦

    vi

    0x002A

    越南语

    vi-VN

    0x042A

    越南语 - 越南

    固定区域性、非特定区域性和特定区域性

    这些区域性通常分为三个集合:固定区域性、非特定区域性和特定区域性。

    固定区域性不区分区域性。可以使用空字符串 ("") 按名称或者按区域性标识符 0x007F 来指定固定区域性。InvariantCulture 检索固定区域性的实例。它与英语语言关联,但不与任何国家/地区关联。它几乎可用在要求区域性的“全局化”命名空间中的所有方法中。

    非特定区域性是与某种语言关联但不与国家/地区关联的区域性。特定区域性是与某种语言和某个国家/地区关联的区域性。例如,“fr”是非特定区域性,而“fr-FR”是特定区域性。注意,“zh-CHS”(简体中文)和“zh-CHT”(繁体中文)均为非特定区域性。

    请注意,不建议为非特定区域性创建 CompareInfo 类的实例,这是因为它包含的数据是任意的。若要显示数据并对其进行排序,请同时指定语言和地区。此外,为非特定区域性创建的 CompareInfo 对象的 Name 属性仅返回国家,且不包括地区。

    区域性有层次结构,即特定区域性的父级是非特定区域性,而非特定区域性的父级是 InvariantCulture。Parent 属性将返回与特定区域性关联的非特定区域性。

    如果特定区域性的资源在系统中不可用,则使用非特定区域性的资源;如果非特定区域性的资源也不可用,那么使用主程序集中嵌入的资源。有关资源备用进程的更多信息,请参见“打包和部署资源”。

    Windows API 中的区域性列表与 .NET Framework 中的区域性列表略有不同。例如,在 Windows API 中未提供带有区域性标识符 0x7C04 的非特定区域性 zh-CHT“中文(繁体)”。如果需要具备同 Windows 进行互操作的能力(例如,通过 p/invoke 机制),可使用在操作系统中定义的特定区域性。这样可以确保与等效的 Windows 区域设置保持一致,它们使用同一 LCID 进行标识。

    只能为固定区域性或特定区域性创建 DateTimeFormatInfo 或 NumberFormatInfo,而不能为非特定区域性创建它们。

    如果 DateTimeFormatInfo.Calendar 是 TaiwanCalendar,但 Thread.CurrentCulture 不是“zh-TW”,则 DateTimeFormatInfo.NativeCalendarName、DateTimeFormatInfo.GetEraName 和 DateTimeFormatInfo.GetAbbreviatedEraName 将返回一个空字符串 ("")。

    Windows 区域设置

    从 .NET Framework 2.0 版开始,CultureInfo 构造函数支持使用 Windows 区域设置(相当于区域性)自动生成 .NET Framework 中不存在的区域性。有关更多信息,请参见 根据 Windows 区域设置生成区域性。

    控制面板重写

    用户可以通过“控制面板”中的“区域和语言选项”(或“区域选项”或“区域设置”)选择重写某些与 Windows 的当前区域性关联的值。例如,用户可能选择以另一种格式显示日期,或选择使用区域性默认设置以外的货币。

    如果 UseUserOverride 为 true 并且指定的区域性与当前 Windows 的区域性匹配,则 CultureInfo 使用那些重写,包括以下属性的用户设置:由 DateTimeFormat 属性返回的 DateTimeFormatInfo 实例的属性以及由 NumberFormat 属性返回的 NumberFormatInfo 实例的属性。如果用户设置与 CultureInfo 的关联区域性不兼容(例如选定的日历不属于 OptionalCalendars 其中之一),则方法结果和属性值是未定义的。

    对于使用欧元的区域性,.NET Framework 和 Windows XP 将默认货币设置为欧元;但是,旧版本的 Windows 却不是这样。因此,如果旧版本 Windows 的用户未通过“控制面板”中的“区域选项”或“区域设置”更改货币设置,则货币可能不正确。若要使用 .NET Framework 的货币的默认设置,请使用接受 useUserOverride 参数的 CultureInfo 构造函数重载,并将该参数设置为 false。

    备用排序顺序

    “西班牙语 - 西班牙”的区域性标识符“0x0c0a”使用默认的国际排序顺序;而区域性标识符“0x040A”(也指“西班牙语 - 西班牙”)则使用传统排序顺序。如果使用“es-ES”区域性名称构造 CultureInfo,则新的 CultureInfo 将使用默认的国际排序顺序。要构造一个使用传统排序顺序的 CultureInfo,可在构造函数中使用区域性标识符“0x040A”。有关具有备用排序方法的其他区域性的更多信息,请参见“针对特定区域性对数据进行比较和排序”。

    实现的接口

    该类实现 ICloneable 接口以启用 CultureInfo 对象的复制。它还实现 IFormatProvider 以便为应用程序提供格式化信息。

    区域性、线程和应用程序域

    在使用与 CultureInfo 对象关联的线程时有着特殊的注意事项。有关区域性和应用程序域的更多信息,请参见 应用程序域和线程。

    TopicLocation如何:为 ASP.NET 网站创建资源文件 如何:为 ASP.NET 网站创建资源文件 (Visual Studio) 如何:为 ASP.NET 网页全球化设置区域性和 UI 区域性 如何:为全球化使用 HTML 标记从右向左显示文本 如何:以编程方式检索资源值  <script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl434d86b9d,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl43img,"; </script> 示例

    下面的代码示例显示如何按国际排序创建一个用于“西班牙语-西班牙”的 CultureInfo,并按传统排序创建另一个 CultureInfo。

    Visual Basic 复制代码 Imports System Imports System.Collections Imports System.Globalization Public Class SamplesCultureInfo Public Shared Sub Main() ' Creates and initializes the CultureInfo which uses the international sort. Dim myCIintl As New CultureInfo("es-ES", False) ' Creates and initializes the CultureInfo which uses the traditional sort. Dim myCItrad As New CultureInfo(&H40A, False) ' Displays the properties of each culture. Console.WriteLine("{0,-33}{1,-25}{2,-25}", "PROPERTY", "INTERNATIONAL", "TRADITIONAL") Console.WriteLine("{0,-33}{1,-25}{2,-25}", "CompareInfo", myCIintl.CompareInfo, myCItrad.CompareInfo) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "DisplayName", myCIintl.DisplayName, myCItrad.DisplayName) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "EnglishName", myCIintl.EnglishName, myCItrad.EnglishName) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "IsNeutralCulture", myCIintl.IsNeutralCulture, myCItrad.IsNeutralCulture) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "IsReadOnly", myCIintl.IsReadOnly, myCItrad.IsReadOnly) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "LCID", myCIintl.LCID, myCItrad.LCID) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "Name", myCIintl.Name, myCItrad.Name) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "NativeName", myCIintl.NativeName, myCItrad.NativeName) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "Parent", myCIintl.Parent, myCItrad.Parent) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "TextInfo", myCIintl.TextInfo, myCItrad.TextInfo) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "ThreeLetterISOLanguageName", myCIintl.ThreeLetterISOLanguageName, myCItrad.ThreeLetterISOLanguageName) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "ThreeLetterWindowsLanguageName", myCIintl.ThreeLetterWindowsLanguageName, myCItrad.ThreeLetterWindowsLanguageName) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "TwoLetterISOLanguageName", myCIintl.TwoLetterISOLanguageName, myCItrad.TwoLetterISOLanguageName) Console.WriteLine() ' Compare two strings using myCIintl. Console.WriteLine("Comparing ""llegar"" and ""lugar""") Console.WriteLine(" With myCIintl.CompareInfo.Compare: {0}", myCIintl.CompareInfo.Compare("llegar", "lugar")) Console.WriteLine(" With myCItrad.CompareInfo.Compare: {0}", myCItrad.CompareInfo.Compare("llegar", "lugar")) End Sub 'Main End Class 'SamplesCultureInfo 'This code produces the following output. ' 'PROPERTY INTERNATIONAL TRADITIONAL 'CompareInfo CompareInfo - 3082 CompareInfo - 1034 'DisplayName Spanish (Spain) Spanish (Spain) 'EnglishName Spanish (Spain) Spanish (Spain) 'IsNeutralCulture False False 'IsReadOnly False False 'LCID 3082 1034 'Name es-ES es-ES 'NativeName español (España) español (España) 'Parent es es 'TextInfo TextInfo - 3082 TextInfo - 1034 'ThreeLetterISOLanguageName spa spa 'ThreeLetterWindowsLanguageName ESN ESN 'TwoLetterISOLanguageName es es ' 'Comparing "llegar" and "lugar" ' With myCIintl.CompareInfo.Compare: -1 ' With myCItrad.CompareInfo.Compare: 1 C# 复制代码 using System; using System.Collections; using System.Globalization; public class SamplesCultureInfo { public static void Main() { // Creates and initializes the CultureInfo which uses the international sort. CultureInfo myCIintl = new CultureInfo( "es-ES", false ); // Creates and initializes the CultureInfo which uses the traditional sort. CultureInfo myCItrad = new CultureInfo( 0x040A, false ); // Displays the properties of each culture. Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "PROPERTY", "INTERNATIONAL", "TRADITIONAL" ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "CompareInfo", myCIintl.CompareInfo, myCItrad.CompareInfo ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "DisplayName", myCIintl.DisplayName, myCItrad.DisplayName ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "EnglishName", myCIintl.EnglishName, myCItrad.EnglishName ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "IsNeutralCulture", myCIintl.IsNeutralCulture, myCItrad.IsNeutralCulture ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "IsReadOnly", myCIintl.IsReadOnly, myCItrad.IsReadOnly ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "LCID", myCIintl.LCID, myCItrad.LCID ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "Name", myCIintl.Name, myCItrad.Name ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "NativeName", myCIintl.NativeName, myCItrad.NativeName ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "Parent", myCIintl.Parent, myCItrad.Parent ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "TextInfo", myCIintl.TextInfo, myCItrad.TextInfo ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "ThreeLetterISOLanguageName", myCIintl.ThreeLetterISOLanguageName, myCItrad.ThreeLetterISOLanguageName ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "ThreeLetterWindowsLanguageName", myCIintl.ThreeLetterWindowsLanguageName, myCItrad.ThreeLetterWindowsLanguageName ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "TwoLetterISOLanguageName", myCIintl.TwoLetterISOLanguageName, myCItrad.TwoLetterISOLanguageName ); Console.WriteLine(); // Compare two strings using myCIintl. Console.WriteLine( "Comparing /"llegar/" and /"lugar/"" ); Console.WriteLine( " With myCIintl.CompareInfo.Compare: {0}", myCIintl.CompareInfo.Compare( "llegar", "lugar" ) ); Console.WriteLine( " With myCItrad.CompareInfo.Compare: {0}", myCItrad.CompareInfo.Compare( "llegar", "lugar" ) ); } } /* This code produces the following output. PROPERTY INTERNATIONAL TRADITIONAL CompareInfo CompareInfo - 3082 CompareInfo - 1034 DisplayName Spanish (Spain) Spanish (Spain) EnglishName Spanish (Spain) Spanish (Spain) IsNeutralCulture False False IsReadOnly False False LCID 3082 1034 Name es-ES es-ES NativeName español (España) español (España) Parent es es TextInfo TextInfo - 3082 TextInfo - 1034 ThreeLetterISOLanguageName spa spa ThreeLetterWindowsLanguageName ESN ESN TwoLetterISOLanguageName es es Comparing "llegar" and "lugar" With myCIintl.CompareInfo.Compare: -1 With myCItrad.CompareInfo.Compare: 1 */ C++ 复制代码 using namespace System; using namespace System::Collections; using namespace System::Globalization; int main() { // Creates and initializes the CultureInfo which uses the international sort. CultureInfo^ myCIintl = gcnew CultureInfo( "es-ES",false ); // Creates and initializes the CultureInfo which uses the traditional sort. CultureInfo^ myCItrad = gcnew CultureInfo( 0x040A,false ); // Displays the properties of each culture. Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "PROPERTY", "INTERNATIONAL", "TRADITIONAL" ); Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "CompareInfo", myCIintl->CompareInfo, myCItrad->CompareInfo ); Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "DisplayName", myCIintl->DisplayName, myCItrad->DisplayName ); Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "EnglishName", myCIintl->EnglishName, myCItrad->EnglishName ); Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "IsNeutralCulture", myCIintl->IsNeutralCulture, myCItrad->IsNeutralCulture ); Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "IsReadOnly", myCIintl->IsReadOnly, myCItrad->IsReadOnly ); Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "LCID", myCIintl->LCID, myCItrad->LCID ); Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "Name", myCIintl->Name, myCItrad->Name ); Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "NativeName", myCIintl->NativeName, myCItrad->NativeName ); Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "Parent", myCIintl->Parent, myCItrad->Parent ); Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "TextInfo", myCIintl->TextInfo, myCItrad->TextInfo ); Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "ThreeLetterISOLanguageName", myCIintl->ThreeLetterISOLanguageName, myCItrad->ThreeLetterISOLanguageName ); Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "ThreeLetterWindowsLanguageName", myCIintl->ThreeLetterWindowsLanguageName, myCItrad->ThreeLetterWindowsLanguageName ); Console::WriteLine( "{0,-33}{1,-25}{2,-25}", "TwoLetterISOLanguageName", myCIintl->TwoLetterISOLanguageName, myCItrad->TwoLetterISOLanguageName ); Console::WriteLine(); // Compare two strings using myCIintl -> Console::WriteLine( "Comparing /"llegar/" and /"lugar/"" ); Console::WriteLine( " With myCIintl -> CompareInfo -> Compare: {0}", myCIintl->CompareInfo->Compare( "llegar", "lugar" ) ); Console::WriteLine( " With myCItrad -> CompareInfo -> Compare: {0}", myCItrad->CompareInfo->Compare( "llegar", "lugar" ) ); } /* This code produces the following output. PROPERTY INTERNATIONAL TRADITIONAL CompareInfo CompareInfo - 3082 CompareInfo - 1034 DisplayName Spanish (Spain) Spanish (Spain) EnglishName Spanish (Spain) Spanish (Spain) IsNeutralCulture False False IsReadOnly False False LCID 3082 1034 Name es-ES es-ES NativeName español (España) español (España) Parent es es TextInfo TextInfo - 3082 TextInfo - 1034 ThreeLetterISOLanguageName spa spa ThreeLetterWindowsLanguageName ESN ESN TwoLetterISOLanguageName es es Comparing "llegar" and "lugar" With myCIintl -> CompareInfo -> Compare: -1 With myCItrad -> CompareInfo -> Compare: 1 */ J# 复制代码 import System.* ; import System.Collections.* ; import System.Globalization.* ; public class SamplesCultureInfo { public static void main(String[] args) { // Creates and initializes the CultureInfo which uses the // international sort. CultureInfo myCIintl = new CultureInfo("es-ES", false); // Creates and initializes the CultureInfo which uses the // traditional sort. CultureInfo myCItrad = new CultureInfo(0x40A, false); // Displays the properties of each culture. Console.WriteLine("{0,-33}{1,-25}{2,-25}", "PROPERTY", "INTERNATIONAL", "TRADITIONAL"); Console.WriteLine("{0,-33}{1,-25}{2,-25}", "CompareInfo", myCIintl.get_CompareInfo(), myCItrad.get_CompareInfo()); Console.WriteLine("{0,-33}{1,-25}{2,-25}", "DisplayName", myCIintl.get_DisplayName(), myCItrad.get_DisplayName()); Console.WriteLine("{0,-33}{1,-25}{2,-25}", "EnglishName", myCIintl.get_EnglishName(), myCItrad.get_EnglishName()); Console.WriteLine("{0,-33}{1,-25}{2,-25}", "IsNeutralCulture", System.Convert.ToString(myCIintl.get_IsNeutralCulture()), System.Convert.ToString(myCItrad.get_IsNeutralCulture())); Console.WriteLine("{0,-33}{1,-25}{2,-25}", "IsReadOnly", System.Convert.ToString(myCIintl.get_IsReadOnly()), System.Convert.ToString(myCItrad.get_IsReadOnly())); Console.WriteLine("{0,-33}{1,-25}{2,-25}", "LCID", System.Convert.ToString(myCIintl.get_LCID()), System.Convert.ToString(myCItrad.get_LCID())); Console.WriteLine("{0,-33}{1,-25}{2,-25}", "Name", myCIintl.get_Name(), myCItrad.get_Name()); Console.WriteLine("{0,-33}{1,-25}{2,-25}", "NativeName", myCIintl.get_NativeName(), myCItrad.get_NativeName()); Console.WriteLine("{0,-33}{1,-25}{2,-25}", "Parent", myCIintl.get_Parent(), myCItrad.get_Parent()); Console.WriteLine("{0,-33}{1,-25}{2,-25}", "TextInfo", myCIintl.get_TextInfo(), myCItrad.get_TextInfo()); Console.WriteLine("{0,-33}{1,-25}{2,-25}", "ThreeLetterISOLanguageName", myCIintl.get_ThreeLetterISOLanguageName(), myCItrad.get_ThreeLetterISOLanguageName()); Console.WriteLine("{0,-33}{1,-25}{2,-25}", "ThreeLetterWindowsLanguageName", myCIintl.get_ThreeLetterWindowsLanguageName(), myCItrad.get_ThreeLetterWindowsLanguageName()); Console.WriteLine("{0,-33}{1,-25}{2,-25}", "TwoLetterISOLanguageName", myCIintl.get_TwoLetterISOLanguageName(), myCItrad.get_TwoLetterISOLanguageName()); Console.WriteLine(); // Compare two strings using myCIintl. Console.WriteLine("Comparing /"llegar/" and /"lugar/""); Console.WriteLine(" With myCIintl.CompareInfo.Compare: {0}", System.Convert.ToString ( myCIintl.get_CompareInfo().Compare( "llegar", "lugar"))); Console.WriteLine(" With myCItrad.CompareInfo.Compare: {0}", System.Convert.ToString ( myCItrad.get_CompareInfo().Compare( "llegar", "lugar"))); } //main } //SamplesCultureInfo /* This code produces the following output. PROPERTY INTERNATIONAL TRADITIONAL CompareInfo CompareInfo - 3082 CompareInfo - 1034 DisplayName Spanish (Spain) Spanish (Spain) EnglishName Spanish (Spain) Spanish (Spain) IsNeutralCulture False False IsReadOnly False False LCID 3082 1034 Name es-ES es-ES NativeName espaol (Espaa) espaol (Espaa) Parent es es TextInfo TextInfo - 3082 TextInfo - 1034 ThreeLetterISOLanguageName spa spa ThreeLetterWindowsLanguageName ESN ESN TwoLetterISOLanguageName es es Comparing "llegar" and "lugar" With myCIintl.CompareInfo.Compare: -1 With myCItrad.CompareInfo.Compare: 1 */

    下面的代码示例使用中文确定每个特定区域性的父区域性。

    Visual Basic 复制代码 Imports System Imports System.Globalization Public Class SamplesCultureInfo Public Shared Sub Main() ' Prints the header. Console.WriteLine("SPECIFIC CULTURE PARENT CULTURE") ' Determines the specific cultures that use the Chinese language, and displays the parent culture. Dim ci As CultureInfo For Each ci In CultureInfo.GetCultures(CultureTypes.SpecificCultures) If ci.TwoLetterISOLanguageName = "zh" Then Console.Write("0x{0} {1} {2,-37}", ci.LCID.ToString("X4"), ci.Name, ci.EnglishName) Console.WriteLine("0x{0} {1} {2}", ci.Parent.LCID.ToString("X4"), ci.Parent.Name, ci.Parent.EnglishName) End If Next ci End Sub 'Main End Class 'SamplesCultureInfo 'This code produces the following output. ' 'SPECIFIC CULTURE PARENT CULTURE '0x0404 zh-TW Chinese (Taiwan) 0x7C04 zh-CHT Chinese (Traditional) '0x0804 zh-CN Chinese (People's Republic of China) 0x0004 zh-CHS Chinese (Simplified) '0x0C04 zh-HK Chinese (Hong Kong S.A.R.) 0x7C04 zh-CHT Chinese (Traditional) '0x1004 zh-SG Chinese (Singapore) 0x0004 zh-CHS Chinese (Simplified) '0x1404 zh-MO Chinese (Macau S.A.R.) 0x7C04 zh-CHT Chinese (Traditional) ' C# 复制代码 using System; using System.Globalization; public class SamplesCultureInfo { public static void Main() { // Prints the header. Console.WriteLine( "SPECIFIC CULTURE PARENT CULTURE" ); // Determines the specific cultures that use the Chinese language, and displays the parent culture. foreach ( CultureInfo ci in CultureInfo.GetCultures( CultureTypes.SpecificCultures ) ) { if ( ci.TwoLetterISOLanguageName == "zh" ) { Console.Write( "0x{0} {1} {2,-37}", ci.LCID.ToString("X4"), ci.Name, ci.EnglishName ); Console.WriteLine( "0x{0} {1} {2}", ci.Parent.LCID.ToString("X4"), ci.Parent.Name, ci.Parent.EnglishName ); } } } } /* This code produces the following output. SPECIFIC CULTURE PARENT CULTURE 0x0404 zh-TW Chinese (Taiwan) 0x7C04 zh-CHT Chinese (Traditional) 0x0804 zh-CN Chinese (People's Republic of China) 0x0004 zh-CHS Chinese (Simplified) 0x0C04 zh-HK Chinese (Hong Kong S.A.R.) 0x7C04 zh-CHT Chinese (Traditional) 0x1004 zh-SG Chinese (Singapore) 0x0004 zh-CHS Chinese (Simplified) 0x1404 zh-MO Chinese (Macau S.A.R.) 0x7C04 zh-CHT Chinese (Traditional) */ C++ 复制代码 using namespace System; using namespace System::Globalization; int main() { // Prints the header. Console::WriteLine( "SPECIFIC CULTURE PARENT CULTURE" ); // Determines the specific cultures that use the Chinese language, // and displays the parent culture. System::Collections::IEnumerator^ en = CultureInfo::GetCultures( CultureTypes::SpecificCultures )->GetEnumerator(); while ( en->MoveNext() ) { CultureInfo^ ci = safe_cast<CultureInfo^>(en->Current); if ( ci->TwoLetterISOLanguageName->Equals( "zh" ) ) { Console::Write( "0x{0} {1} {2,-37}", ci->LCID.ToString( "X4" ), ci->Name, ci->EnglishName ); Console::WriteLine( "0x{0} {1} {2}", ci->Parent->LCID.ToString( "X4" ), ci->Parent->Name, ci->Parent->EnglishName ); } } } /* This code produces the following output. SPECIFIC CULTURE PARENT CULTURE 0x0404 zh-TW Chinese (Taiwan) 0x7C04 zh-CHT Chinese (Traditional) 0x0804 zh-CN Chinese (People's Republic of China) 0x0004 zh-CHS Chinese (Simplified) 0x0C04 zh-HK Chinese (Hong Kong S.A.R.) 0x7C04 zh-CHT Chinese (Traditional) 0x1004 zh-SG Chinese (Singapore) 0x0004 zh-CHS Chinese (Simplified) 0x1404 zh-MO Chinese (Macao S.A.R.) 0x0004 zh-CHS Chinese (Simplified) */ J# 复制代码 import System.* ; import System.Globalization.* ; public class SamplesCultureInfo { public static void main(String[] args) { // Prints the header. Console.WriteLine("SPECIFIC CULTURE " + " PARENT CULTURE"); // Determines the specific cultures that use the Chinese language, // and displays the parent culture. for(int iCtr=0; iCtr < (CultureInfo.GetCultures(CultureTypes.SpecificCultures). length); iCtr++) { CultureInfo ci = CultureInfo.GetCultures(CultureTypes.SpecificCultures)[iCtr]; if (ci.get_TwoLetterISOLanguageName().equalsIgnoreCase("zh")) { Console.Write("0x{0} {1} {2,-37}", ((System.Int32 ) ci.get_LCID()).ToString("X4") , ci.get_Name(), ci.get_EnglishName()); Console.WriteLine("0x{0} {1} {2}", ((System.Int32 )ci.get_Parent().get_LCID()).ToString("X4"), ci.get_Parent().get_Name(), ci.get_Parent().get_EnglishName()); } } } //main } //SamplesCultureInfo /* This code produces the following output. SPECIFIC CULTURE PARENT CULTURE 0x0404 zh-TW Chinese (Taiwan) 0x7C04 zh-CHT Chinese (Traditional) 0x0804 zh-CN Chinese (People's Republic of China) 0x0004 zh-CHS Chinese (Simplified) 0x0C04 zh-HK Chinese (Hong Kong S.A.R.) 0x7C04 zh-CHT Chinese (Traditional) 0x1004 zh-SG Chinese (Singapore) 0x0004 zh-CHS Chinese (Simplified) 0x1404 zh-MO Chinese (Macau S.A.R.) 0x0004 zh-CHS Chinese (Simplified) */ <script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl529e73343,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl52img,"; </script> 继承层次结构 System.Object    System.Globalization.CultureInfo <script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl54e84a15a,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl54img,"; </script> 线程安全 此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。 <script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl55cf1f481,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl55img,"; </script> 平台

    Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

    .NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。

    <script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl57a95a6b9,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl57img,"; </script> 版本信息

    .NET Framework

    受以下版本支持:2.0、1.1、1.0

    .NET Compact Framework

    受以下版本支持:2.0、1.0 <script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl58a88fdae,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl58img,"; </script> 请参见

    参考

    CultureInfo 成员 System.Globalization 命名空间 RegionInfo  

    最新回复(0)