Freigeben über


CultureInfo Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Provides information about a specific culture. The information includes the names for the culture, the writing system, the calendar used, the formatting used for numbers and dates, and the order of sorted strings.

Inheritance Hierarchy

System.Object
  System.Globalization.CultureInfo

Namespace:  System.Globalization
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<ComVisibleAttribute(True)> _
Public Class CultureInfo _
    Implements IFormatProvider
[ComVisibleAttribute(true)]
public class CultureInfo : IFormatProvider

The CultureInfo type exposes the following members.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 CultureInfo Initializes a new instance of the CultureInfo class based on the culture specified by name.

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Calendar Gets the default calendar used by the culture.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 CompareInfo Gets the CompareInfo object that defines how to compare strings for the culture.
Public propertyStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 CurrentCulture Gets the CultureInfo object that represents the culture used by the current thread.
Public propertyStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 CurrentUICulture Gets the CultureInfo object that represents the current culture used by the Resource Manager to look up culture-specific resources at run time.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 DateTimeFormat Gets or sets a DateTimeFormatInfo object that defines the culturally appropriate format for converting dates and times to strings.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 DisplayName Gets the culture name in the format "language (country/region)" in the language of the localized version of .NET Framework.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 EnglishName Gets the culture name in the format "language (country/region)" in English.
Public propertyStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 InvariantCulture Gets the CultureInfo that is culture-independent (invariant).
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsNeutralCulture Gets a value indicating whether the current CultureInfo object represents a neutral culture.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsReadOnly Gets a value indicating whether the current CultureInfo object is read-only.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Name Gets the culture name in the format "languagecode-country/regioncode".
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 NativeName Gets the culture's native name, which consists of the language, the country/region, and the optional script, that the culture is set to display.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 NumberFormat Gets or sets a NumberFormatInfo object that defines the culturally appropriate format for converting numbers, currency values, and percentages to strings.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 OptionalCalendars Gets the list of calendars that can be used by this culture.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Parent Gets the CultureInfo that represents the parent culture of the current CultureInfo.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 TextInfo Gets the TextInfo object that defines the writing system associated with the culture.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 TwoLetterISOLanguageName Gets the ISO 639-1 two-letter code for the language of the current CultureInfo.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Clone Creates a copy of the current CultureInfo object.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Equals Determines whether the specified object is the same culture as this CultureInfo object. (Overrides Object.Equals(Object).)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetFormat Gets an object that defines how to format the specified type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetHashCode Serves as a hash function for the current CultureInfo, suitable for hashing algorithms and data structures, such as a hash table. (Overrides Object.GetHashCode().)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetType Gets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 ReadOnly Returns a read-only wrapper around the specified CultureInfo object.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 ToString Returns a string containing the name of the current CultureInfo object in the format "languagecode-country/regioncode". (Overrides Object.ToString().)

Top

Remarks

The CultureInfo class provides culture-specific information, such as the associated language, sublanguage, country/region, calendar, and cultural conventions. This class also provides access to culture-specific instances of DateTimeFormatInfo, NumberFormatInfo, CompareInfo, and TextInfo. These objects contain the information required for culture-specific operations, such as casing, formatting dates and numbers, and comparing strings.

The members of the String class either directly or indirectly use this class to obtain information about the default culture.

NoteNote:

CultureInfo objects other than CultureInfo.InvariantCulture retrieve their data from the operating system. As a result, the values of individual CultureInfo properties may differ not only by operating system, but also within versions of the same operating system.

Culture Names and Identifiers

The CultureInfo class specifies a unique name for each culture, based on RFC 4646. The name is a combination of an ISO 639 two-letter lowercase culture code associated with a language and an ISO 3166 two-letter uppercase subculture code associated with a country or region. The format for the culture name is "languagecode-country/regioncode", where languagecode is the language code and country/regioncode is the subculture code. Examples include "ja-JP" for Japanese (Japan) and "en-US" for English (United States). In cases where a two-letter language code is not available, a three-letter code derived from ISO 639-2 is used.

Some culture names also specify an ISO 15924 script. For example, "-Cyrl" specifies the Cyrillic script and "-Latn" specifies the Latin script. A culture name including a script is rendered using the pattern "languagecode-scripttag-country/regioncode". An example of this type of culture name is "uz-Cyrl-UZ" for Uzbek (Uzbekistan, Cyrillic).

A neutral culture (a culture defined by a language with no specific country/region) is specified by the two-letter lowercase language code only. For example, "fr" specifies the neutral culture for French, and "de" specifies the neutral culture for German.

NoteNote:

There are two culture names that contradict this rule. The cultures "zh-Hans" (Simplified Chinese) and "zh-Hant" (Traditional Chinese) are neutral cultures.

The following table lists the predefined culture names that are recognized by the .NET Framework for Silverlight and that can be used when instantiating a CultureInfo object. However, because the .NET Framework for Silverlight retrieves culture information from the operating system, the availability of cultural information may vary depending on the platform and operating system version.

Culture/language name

Culture

"" (empty string)

Invariant culture

af

Afrikaans

af-ZA

Afrikaans (South Africa)

sq

Albanian

sq-AL

Albanian (Albania)

ar

Arabic

ar-DZ

Arabic (Algeria)

ar-BH

Arabic (Bahrain)

ar-EG

Arabic (Egypt)

ar-IQ

Arabic (Iraq)

ar-JO

Arabic (Jordan)

ar-KW

Arabic (Kuwait)

ar-LB

Arabic (Lebanon)

ar-LY

Arabic (Libya)

ar-MA

Arabic (Morocco)

ar-OM

Arabic (Oman)

ar-QA

Arabic (Qatar)

ar-SA

Arabic (Saudi Arabia)

ar-SY

Arabic (Syria)

ar-TN

Arabic (Tunisia)

ar-AE

Arabic (U.A.E.)

ar-YE

Arabic (Yemen)

hy

Armenian

hy-AM

Armenian (Armenia)

az

Azeri

az-Cyrl-AZ

Azeri (Azerbaijan, Cyrillic)

az-Latn-AZ

Azeri (Azerbaijan, Latin)

eu

Basque

eu-ES

Basque (Basque)

be

Belarusian

be-BY

Belarusian (Belarus)

bg

Bulgarian

bg-BG

Bulgarian (Bulgaria)

ca

Catalan

ca-ES

Catalan (Catalan)

zh-HK

Chinese (Hong Kong SAR, PRC)

zh-MO

Chinese (Macao SAR)

zh-CN

Chinese (PRC)

zh-Hans

Chinese (Simplified)

zh-SG

Chinese (Singapore)

zh-TW

Chinese (Taiwan)

zh-Hant

Chinese (Traditional)

hr

Croatian

hr-BA

Croatian (Bosnia and Herzegovina)

hr-HR

Croatian (Croatia)

cs

Czech

cs-CZ

Czech (Czech Republic)

da

Danish

da-DK

Danish (Denmark)

dv

Divehi

dv-MV

Divehi (Maldives)

nl

Dutch

nl-BE

Dutch (Belgium)

nl-NL

Dutch (Netherlands)

en

English

en-AU

English (Australia)

en-BZ

English (Belize)

en-CA

English (Canada)

en-029

English (Caribbean)

en-IE

English (Ireland)

en-JM

English (Jamaica)

en-NZ

English (New Zealand)

en-PH

English (Philippines)

en-ZA

English (South Africa

en-TT

English (Trinidad and Tobago)

en-GB

English (United Kingdom)

en-US

English (United States)

en-ZW

English (Zimbabwe)

et

Estonian

et-EE

Estonian (Estonia)

fo

Faroese

fo-FO

Faroese (Faroe Islands)

fa

Farsi

fa-IR

Farsi (Iran)

fi

Finnish

fi-FI

Finnish (Finland)

fr

French

fr-BE

French (Belgium)

fr-CA

French (Canada)

fr-FR

French (France)

fr-LU

French (Luxembourg)

fr-MC

French (Monaco)

fr-CH

French (Switzerland)

gl

Galician

gl-ES

Galician (Spain)

ka

Georgian

ka-GE

Georgian (Georgia)

de

German

de-AT

German (Austria)

de-DE

German (Germany)

de-DE_phoneb

German (Germany, phone book sort)

de-LI

German (Liechtenstein)

de-LU

German (Luxembourg)

de-CH

German (Switzerland)

el

Greek

el-GR

Greek (Greece)

gu

Gujarati

gu-IN

Gujarati (India)

he

Hebrew

he-IL

Hebrew (Israel)

hi

Hindi

hi-IN

Hindi (India)

hu

Hungarian

hu-HU

Hungarian (Hungary)

is

Icelandic

is-IS

Icelandic (Iceland)

id

Indonesian

id-ID

Indonesian (Indonesia)

it

Italian

it-IT

Italian (Italy)

it-CH

Italian (Switzerland)

ja

Japanese

ja-JP

Japanese (Japan)

kn

Kannada

kn-IN

Kannada (India)

kk

Kazakh

kk-KZ

Kazakh (Kazakhstan)

kok

Konkani

kok-IN

Konkani (India)

ko

Korean

ko-KR

Korean (Korea)

ky

Kyrgyz

ky-KG

Kyrgyz (Kyrgyzstan)

lv

Latvian

lv-LV

Latvian (Latvia)

lt

Lithuanian

lt-LT

Lithuanian (Lithuania)

mk

Macedonian

mk-MK

Macedonian (Macedonia, FYROM)

ms

Malay

ms-BN

Malay (Brunei Darussalam)

ms-MY

Malay (Malaysia)

mr

Marathi

mr-IN

Marathi (India)

mn

Mongolian

mn-MN

Mongolian (Mongolia)

no

Norwegian

nb-NO

Norwegian (Bokmål, Norway)

nn-NO

Norwegian (Nynorsk, Norway)

pl

Polish

pl-PL

Polish (Poland)

pt

Portuguese

pt-BR

Portuguese (Brazil)

pt-PT

Portuguese (Portugal)

pa

Punjabi

pa-IN

Punjabi (India)

ro

Romanian

ro-RO

Romanian (Romania)

ru

Russian

ru-RU

Russian (Russia)

sa

Sanskrit

sa-IN

Sanskrit (India)

sr-Cyrl-CS

Serbian (Serbia, Cyrillic)

sr-Latn-CS

Serbian (Serbia, Latin)

sk

Slovak

sk-SK

Slovak (Slovakia)

sl

Slovenian

sl-SI

Slovenian (Slovenia)

es

Spanish

es-AR

Spanish (Argentina)

es-BO

Spanish (Bolivia)

es-CL

Spanish (Chile)

es-CO

Spanish (Colombia)

es-CR

Spanish (Costa Rica)

es-DO

Spanish (Dominican Republic)

es-EC

Spanish (Ecuador)

es-SV

Spanish (El Salvador)

es-GT

Spanish (Guatemala)

es-HN

Spanish (Honduras)

es-MX

Spanish (Mexico)

es-NI

Spanish (Nicaragua)

es-PA

Spanish (Panama)

es-PY

Spanish (Paraguay)

es-PE

Spanish (Peru)

es-PR

Spanish (Puerto Rico)

es-ES

Spanish (Spain)

es-ES_tradnl

Span (Span, Traditional Sort)

es-UY

Spanish (Uruguay)

es-VE

Spanish (Venezuela)

sw

Swahili

sw-KE

Swahili (Kenya)

sv

Swedish

sv-FI

Swedish (Finland)

sv-SE

Swedish (Sweden)

syr

Syriac

syr-SY

Syriac (Syria)

ta

Tamil

ta-IN

Tamil (India)

tt

Tatar

tt-RU

Tatar (Russia)

te

Telugu

te-IN

Telugu (India)

th

Thai

th-TH

Thai (Thailand)

tr

Turkish

tr-TR

Turkish (Turkey)

uk

Ukrainian

uk-UA

Ukrainian (Ukraine)

ur

Urdu

ur-PK

Urdu (Pakistan)

uz

Uzbek

uz-Cyrl-UZ

Uzbek (Uzbekistan, Cyrillic)

uz-Latn-UZ

Uzbek (Uzbekistan, Latin)

vi

Vietnamese

vi-VN

Vietnamese (Vietnam)

Several distinct names are closely associated with a culture, notably the names associated with the following class members:

  • CultureInfo.ToString

    Typically, this is a "normalized" version of the string that is passed to the CultureInfo class constructor. Its language component is always lowercased and its country/region component is always uppercased.

  • CultureInfo.Name

    This name represents the language and country/region component of the CultureInfo object together with a script, if one is present. It does not include sort order information if the CultureInfo object was instantiated with a string that defines a particular sort order.

  • CompareInfo.Name

    This name represents the language and country/region component together with a component script, if one is present, and an indication of the sort order, if it is relevant.

Invariant, Neutral, and Specific Cultures

The cultures are generally grouped into three sets: invariant cultures, neutral cultures, and specific cultures.

An invariant culture is culture-insensitive. Your application specifies the invariant culture by name using an empty string ("") or by its identifier. InvariantCulture defines an instance of the invariant culture. It is associated with the English language but not with any country/region. It is used in almost any method in the System.Globalization namespace that requires a culture.

A neutral culture is a culture that is associated with a language but not with a country/region. A specific culture is a culture that is associated with a language and a country/region. For example, "fr" is a neutral culture and "fr-FR" is a specific culture. Note that "zh-Hans" (Simplified Chinese) and "zh-Hant" (Traditional Chinese) are neutral cultures.

Creating an instance of a CompareInfo class for a neutral culture is not recommended because the data it contains is arbitrary. To display and sort data, specify both the language and region.

The defined cultures have a hierarchy in which the parent of a specific culture is a neutral culture and the parent of a neutral culture is the invariant culture. The Parent property contains the neutral culture associated with a specific culture. Custom cultures should define the Parent property in conformance with this pattern.

If DateTimeFormatInfo.Calendar is the TaiwanCalendar but the Thread.CurrentCulture is not "zh-TW", then DateTimeFormatInfo.GetEraName and DateTimeFormatInfo.GetAbbreviatedEraName return an empty string ("").

Custom Cultures

When preparing software to handle custom cultures, consider the following:

  • Custom cultures can have values that exceed the ranges of the Microsoft-shipped cultures. For example, some cultures have unusually long month names, unexpected date or time formats, or other unusual data.

  • Respect the user's culture data values; for example, the user might want a 24-hour clock or a yyyyMMdd date format.

  • Remember that custom cultures override default values. Therefore, you cannot consider culture data to be stable. Country names, date formats, and spellings will probably change in the future.

Dynamic Culture Data

Except for the invariant culture, culture data is dynamic. This is true even for the predefined cultures. For example, countries or regions adopt new currencies, change their spellings of words, or change their preferred calendar, and culture definitions change to track this. Custom cultures are subject to change without notice, and any specific culture might be overridden by a custom replacement culture. An individual user can also override cultural preferences. Applications should always obtain culture data at run time.

Implemented Interfaces

This class implements IFormatProvider to supply formatting information to applications.

Examples

The following example determines the parent culture of each specific culture that uses the Chinese language.

Imports System.Globalization

Public Class Example

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      ' Prints the header.
      outputBlock.FontFamily = New System.Windows.Media.FontFamily("Courier New")
      outputBlock.Text &= "SPECIFIC CULTURE                             PARENT CULTURE" & vbCrLf

      ' Create an array of Chinese culture names.
      Dim cultureNames() As String = { "zh-CN", "zh-Hans", "zh-Hant", "zh-HK", _  
                                       "zh-MO", "zh-SG", "zh-TW" }

      ' Determines the specific cultures that use the Chinese language, and displays the parent culture.
      For Each cultureName As String In cultureNames
         Dim ci As New CultureInfo(cultureName) 
         outputBlock.Text &= String.Format("{0,-7} {1,-37}", ci.Name, ci.EnglishName)
         outputBlock.Text &= String.Format("{0,-7} {1}", ci.Parent.Name, ci.Parent.EnglishName) & vbCrLf
      Next 
   End Sub 
End Class 
' This example produces the following output.
'    SPECIFIC CULTURE                             PARENT CULTURE
'    zh-CN   Chinese (People's Republic of China) zh-Hans Chinese 
'    zh-Hans Chinese                                      Invariant Language (Invariant Country)
'    zh-Hant Chinese                                      Invariant Language (Invariant Country)
'    zh-HK   Chinese (Hong Kong S.A.R.)           zh-Hant Chinese 
'    zh-MO   Chinese (Macao S.A.R.)               zh-Hant Chinese 
'    zh-SG   Chinese (Singapore)                  zh-Hans Chinese 
'    zh-TW   Chinese (Taiwan)                     zh-Hant Chinese 
using System;
using System.Globalization;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Displays the header.
      outputBlock.FontFamily = new System.Windows.Media.FontFamily("Courier New");
      outputBlock.Text += "SPECIFIC CULTURE                             PARENT CULTURE" + "\n";

      // Create an array of Chinese culture names.
      string[] cultureNames = { "zh-CN", "zh-Hans", "zh-Hant", "zh-HK",  
                                "zh-MO", "zh-SG", "zh-TW", };

      // Determines the specific cultures that use the Chinese language, and displays the parent culture.
      foreach (string cultureName in cultureNames)
      {
         CultureInfo ci = new CultureInfo(cultureName);
         outputBlock.Text += String.Format("{0,-7} {1,-37}", ci.Name, ci.EnglishName);
         outputBlock.Text += String.Format("{0,-7} {1}\n", ci.Parent.Name, ci.Parent.EnglishName);
      }
   }
}
/*
This example produces the following output.

SPECIFIC CULTURE                             PARENT CULTURE
zh-CN   Chinese (People's Republic of China) zh-Hans Chinese 
zh-Hans Chinese                                      Invariant Language (Invariant Country)
zh-Hant Chinese                                      Invariant Language (Invariant Country)
zh-HK   Chinese (Hong Kong S.A.R.)           zh-Hant Chinese 
zh-MO   Chinese (Macao S.A.R.)               zh-Hant Chinese 
zh-SG   Chinese (Singapore)                  zh-Hans Chinese 
zh-TW   Chinese (Taiwan)                     zh-Hant Chinese 
*/

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.