按一下以給予評分及指教
MSDN
MSDN Library
.NET 開發
先前版本
類別庫參考

  開啟低頻寬檢視
本頁僅適用於
Microsoft Visual Studio 2005/.NET Framework 2.0

其他版本也適用於下列軟體:
.NET Framework 類別庫
CultureInfo 類別

提供特定文化特性 (Culture) 的相關資訊,如文化特性名稱、書寫系統、使用的行事曆,以及如何格式化日期和排序字串。

命名空間: System.Globalization
組件: mscorlib (在 mscorlib.dll 中)

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

CultureInfo 類別具有特定文化特性的資訊,例如相關的語言、次語言 (Sublanguage)、國家/地區、曆法和文化慣例。這個類別也提供對 DateTimeFormatInfoNumberFormatInfoCompareInfoTextInfo 的特定文化特性執行個體的存取。這些物件包含特定文化特性作業所需的資訊,例如大小寫的指定、日期和數字的格式化,以及字串的比較。

String 類別間接使用這個類別來取得預設文化特性的資訊。

文化特性名稱和識別項

文化特性名稱遵循 "<languagecode2>-<country/regioncode2>" 格式的 RFC 1766 標準,其中,<languagecode2> 為衍生自 ISO 639-1 的兩個小寫字母代碼,而 <country/regioncode2> 為衍生自 ISO 3166 的兩個大寫字母代碼。例如,美式英語 (U.S. English) 會以 "en-US" 表示。在沒有兩個字母的語言代碼可用的情況下,便要使用衍生自 ISO 639-2 的三字母代碼;例如,三字母代碼「div」用於使用迪培希 (Dhivehi) 語言的文化特性。某些文化特性名稱具有指定指令碼的尾碼;例如,"-Cyrl" 指定斯拉夫文指令碼,"-Latn" 指定拉丁文指令碼。

下列預先定義的文化特性名稱和識別項為 System.Globalization 命名空間中的這個類別 (Class) 和其他類別所接受並使用。

文化特性名稱

文化特性識別項

語言 - 國家/地區

"" (空字串)

0x007F

不變文化特性 (Invariant Culture)

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

蒙古文 - 蒙古

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 會擷取不因文化特性而異的執行個體。它會與英語相關聯,但不會與國別/區域相關聯。它幾乎可用於要求文化特性的 Globalization 命名空間中的所有方法。

中性文化特性是與語言相關聯的文化特性,但不與國別/區域相關聯。特定文化特性是與語言和國別/區域相關聯的文化特性。例如,"fr" 是中性文化特性,而 "fr-FR" 是特定文化特性。請注意 "zh-CHS" (簡體中文) 和 "zh-CHT" (繁體中文) 都是中性文化特性。

請注意,不建議您針對中性文化特性建立 CompareInfo 類別的執行個體,因為它所包含的資料是任意的。若要顯示並排序資料,請同時指定語言和地區。此外,針對中性文化特性所建立之 CompareInfo 物件的 Name 屬性只會傳回國家但不會包含地區。

文化特性具有這樣的階層架構,使得特定文化特性的父項會是中性文化特性,而中性文化特性的父項又是 InvariantCultureParent 屬性會傳回與特定文化特性相關聯的中性文化特性。

如果在系統中無法使用特定文化特性的資源,則會使用中性文化特性的資源,如果無法使用中性文化特性的資源,則會使用主要組件的內嵌資源。如需資源回溯過程的詳細資訊,請參閱 封裝和部署資源 (資源的回溯過程)。

Windows API 中的文化特性清單與 .NET Framework 中的文化特性清單稍微不同。例如,Windows API 沒有提供具文化特性識別項 0x7C04 的中性文化特性 zh-CHT「中文 (繁體)」。如果需要有與 Windows 之間的互通性 (例如,透過 p/invoke 機制),請使用作業系統中定義的特定文化特性。這將確保能夠與對等的 Windows 地區設定 (Locale) 一致,該地區設定是用相同的 LCID 來識別。

DateTimeFormatInfoNumberFormatInfo 只可以為不因文化特性而異 (Invariant Culture) 或特定文化特性 (Culture) 建立,而不可為中性文化特性建立。

如果 DateTimeFormatInfo.CalendarTaiwanCalendar,但是 Thread.CurrentCulture 並非 "zh-TW",則 DateTimeFormatInfo.NativeCalendarNameDateTimeFormatInfo.GetEraNameDateTimeFormatInfo.GetAbbreviatedEraName 將傳回空字串 ("")。

Windows 地區設定

從 .NET Framework 2.0 版開始,CultureInfo 建構函式 (Constructor) 支援使用等同於文化特性的 Windows 地區設定,自動產生 .NET Framework 中不存在的文化特性。如需詳細資訊,請參閱 從 Windows 地區設定產生的文化特性

控制台覆寫

使用者可能會選擇透過 [控制台] 中的 [區域及語言選項] (或 [地區選項或地區設定]),覆寫一些與 Windows 的目前文化特性相關聯的值。例如,使用者可能選擇以不同的格式顯示日期,或使用不同於文化特性預設值的貨幣。

如果 UseUserOverridetrue,且指定的文化特性符合 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,請在建構函式 (Constructor) 中使用文化特性識別項「0x040A」。如需其他具有替代排序順序之文化特性的詳細資訊,請參閱 比較和排序特定文化特性的資料 (使用另一種排序順序)。

已實作的介面

這個類別會實作 ICloneable 介面來啟用 CultureInfo 物件的複製。它也實作 IFormatProvider 來提供格式資訊給應用程式。

文化特性、執行緒和應用程式定義域

使用與 CultureInfo 物件相關聯的執行緒時,有一些獨特的考量事項。如需文化特性和應用程式定義域的詳細資訊,請參閱應用程式定義域和執行緒

TopicLocation
HOW TO:以程式設計方式擷取資源值建置 ASP .NET Web 應用程式
HOW TO:以程式設計方式擷取資源值在 Visual Studio 中建立 ASP .NET Web 應用程式
HOW TO:建立 ASP.NET Web 網頁的資源檔 (Visual Studio)在 Visual Studio 中建置 ASP .NET Web 應用程式
HOW TO:建立 ASP.NET Web 網頁的資源檔 (Visual Studio)在 Visual Studio 中建立 ASP .NET Web 應用程式
HOW TO:建立 ASP.NET 網站的資源檔建置 ASP .NET Web 應用程式
HOW TO:設定 ASP.NET Web 網頁全球化的文化特性和 UI 文化特性建置 ASP .NET Web 應用程式
HOW TO:設定 ASP.NET Web 網頁全球化的文化特性和 UI 文化特性在 Visual Studio 中建立 ASP .NET Web 應用程式
HOW TO:針對全球化使用 HTML 標記由右至左顯示文字建置 ASP .NET Web 應用程式
HOW TO:針對全球化使用 HTML 標記由右至左顯示文字在 Visual Studio 中建立 ASP .NET Web 應用程式

下列程式碼範例顯示如何建立使用國際排序的「西班牙文-西班牙」的 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)
*/
System.Object
  System.Globalization.CultureInfo
這個型別的所有公用靜態成員 (即 Visual Basic 中的 Shared 成員) 都是安全執行緒。並非所有的執行個體成員均為安全執行緒。

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 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱系統需求一節的內容。

.NET Framework

支援版本:2.0、1.1、1.0

.NET Compact Framework

支援版本:2.0、1.0
社群內容   什麼是社群內容?
新增內容 RSS  註解
Processing
© 2009 Microsoft Corporation. 著作權所有,並保留一切權利。 使用規定  |  商標  |  隱私權聲明
Page view tracker