Export (0) Print
Expand All
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

CultureInfo Class

July 28, 2014

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.

System.Object
  System.Globalization.CultureInfo

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

public class CultureInfo : IFormatProvider

The CultureInfo type exposes the following members.

  NameDescription
Public methodCultureInfoInitializes a new instance of the CultureInfo class based on the culture specified by name.
Top

  NameDescription
Public propertyCalendarGets the default calendar used by the culture.
Public propertyCompareInfoGets the CompareInfo object that defines how to compare strings for the culture.
Public propertyStatic memberCurrentCultureGets the CultureInfo object that represents the culture used by the current thread.
Public propertyStatic memberCurrentUICultureGets the CultureInfo object that represents the current culture used by the Resource Manager to look up culture-specific resources at run time.
Public propertyDateTimeFormatGets or sets a DateTimeFormatInfo object that defines the culturally appropriate format for converting dates and times to strings.
Public propertyStatic memberDefaultThreadCurrentCultureGets or sets the default culture for threads in the current application domain.
Public propertyStatic memberDefaultThreadCurrentUICultureGets or sets the default UI culture for threads in the current application domain.
Public propertyDisplayNameGets the culture name in the format "language (country/region)" in the language of the localized version of .NET Framework.
Public propertyEnglishNameGets the culture name in the format "language (country/region)" in English.
Public propertyStatic memberInvariantCultureGets the CultureInfo that is culture-independent (invariant).
Public propertyIsNeutralCultureGets a value indicating whether the current CultureInfo object represents a neutral culture.
Public propertyIsReadOnlyGets a value indicating whether the current CultureInfo object is read-only.
Public propertyNameGets the culture name in the format "languagecode-country/regioncode".
Public propertyNativeNameGets 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 propertyNumberFormatGets or sets a NumberFormatInfo object that defines the culturally appropriate format for converting numbers, currency values, and percentages to strings.
Public propertyOptionalCalendarsGets the list of calendars that can be used by this culture.
Public propertyParentGets the CultureInfo that represents the parent culture of the current CultureInfo.
Public propertyTextInfoGets the TextInfo object that defines the writing system associated with the culture.
Public propertyTwoLetterISOLanguageNameGets the ISO 639-1 two-letter code for the language of the current CultureInfo.
Top

  NameDescription
Public methodCloneCreates a copy of the current CultureInfo object.
Public methodEqualsDetermines whether the specified object is the same culture as this CultureInfo object. (Overrides Object.Equals(Object).)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetFormatGets an object that defines how to format the specified type.
Public methodGetHashCodeServes as a hash function for the current CultureInfo, suitable for hashing algorithms and data structures, such as a hash table. (Overrides Object.GetHashCode().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodStatic memberReadOnlyReturns a read-only wrapper around the specified CultureInfo object.
Public methodToStringReturns a string containing the name of the current CultureInfo object in the format "languagecode-country/regioncode". (Overrides Object.ToString().)
Top

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.

NoteNote:

The case of a culture name is not significant when it is passed to the CultureInfo class constructor.

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 and that can be used when instantiating a CultureInfo object. However, because the .NET Framework 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.

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


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 
*/


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

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

Show:
© 2014 Microsoft