Export (0) Print
Expand All
26 out of 81 rated this helpful - Rate this topic

CultureInfo Class

Provides information about a specific culture (called a "locale" for unmanaged code development). The information includes the names for the culture, the writing system, the calendar used, and formatting for dates and sort strings.

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

[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public class CultureInfo : ICloneable, IFormatProvider
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class CultureInfo implements ICloneable, IFormatProvider
SerializableAttribute 
ComVisibleAttribute(true) 
public class CultureInfo implements ICloneable, IFormatProvider
Not applicable.

The CultureInfo class renders 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 String class indirectly uses this class to obtain information about the default culture.

Culture Names and Identifiers

The CultureInfo class specifies a unique name for each culture, based on RFC 4646 (Windows Vista and later). 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 "<languagecode2>-<country/regioncode2>", where <languagecode2> is the language code and <country/regioncode2> 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.

Note that some culture names also specify an ISO 15924 script. For example, "-Cyrl" specifies the Cyrillic script and "-Latn" specifies the Latin script. On Windows Vista and later, a culture name including a script is rendered using the pattern <languagecode2>-<scripttag>-<country/regioncode2>. An example of this type of culture name is uz-Cyrl-UZ for Uzbek (Uzbekistan, Cyrillic). On pre-Windows Vista operating systems, a culture name including a script is rendered using the pattern <languagecode2>-<country/regioncode2>-<scripttag>, for example, uz-UZ-Cyrl for Uzbek (Uzbekistan, Cyrillic).

A neutral culture is specified by only the two-digit lowercase language code. 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 culture names represent the current standard and should be used unless you have a reason for using the older names "zh-CHS" and "zh-CHT".

The following predefined culture names and identifiers are accepted and used by this and other classes in the System.Globalization namespace. Remember that the culture names shown below represent only a subset of cultures that can be found on a particular computer. Windows versions or service packs can change the available cultures. Applications add custom cultures using the CultureAndRegionInfoBuilder class. Users add their own custom cultures using the Microsoft Locale Builder tool. Microsoft Locale Builder is written in managed code using the CultureAndRegionInfoBuilder class.

Culture/Language Name

Culture Identifier

Culture

"" (empty string)

0x007F

Invariant culture

af

0x0036

Afrikaans

af-ZA

0x0436

Afrikaans (South Africa)

sq

0x001C

Albanian

sq-AL

0x041C

Albanian (Albania)

ar

0x0001

Arabic

ar-DZ

0x1401

Arabic (Algeria)

ar-BH

0x3C01

Arabic (Bahrain)

ar-EG

0x0C01

Arabic (Egypt)

ar-IQ

0x0801

Arabic (Iraq)

ar-JO

0x2C01

Arabic (Jordan)

ar-KW

0x3401

Arabic (Kuwait)

ar-LB

0x3001

Arabic (Lebanon)

ar-LY

0x1001

Arabic (Libya)

ar-MA

0x1801

Arabic (Morocco)

ar-OM

0x2001

Arabic (Oman)

ar-QA

0x4001

Arabic (Qatar)

ar-SA

0x0401

Arabic (Saudi Arabia)

ar-SY

0x2801

Arabic (Syria)

ar-TN

0x1C01

Arabic (Tunisia)

ar-AE

0x3801

Arabic (U.A.E.)

ar-YE

0x2401

Arabic (Yemen)

hy

0x002B

Armenian

hy-AM

0x042B

Armenian (Armenia)

az

0x002C

Azeri

az-Cyrl-AZ

0x082C

Azeri (Azerbaijan, Cyrillic)

az-Latn-AZ

0x042C

Azeri (Azerbaijan, Latin)

eu

0x002D

Basque

eu-ES

0x042D

Basque (Basque)

be

0x0023

Belarusian

be-BY

0x0423

Belarusian (Belarus)

bg

0x0002

Bulgarian

bg-BG

0x0402

Bulgarian (Bulgaria)

ca

0x0003

Catalan

ca-ES

0x0403

Catalan (Catalan)

zh-HK

0x0C04

Chinese (Hong Kong SAR, PRC)

zh-MO

0x1404

Chinese (Macao SAR)

zh-CN

0x0804

Chinese (PRC)

zh-Hans

0x0004

Chinese (Simplified)

zh-SG

0x1004

Chinese (Singapore)

zh-TW

0x0404

Chinese (Taiwan)

zh-Hant

0x7C04

Chinese (Traditional)

hr

0x001A

Croatian

hr-HR

0x041A

Croatian (Croatia)

cs

0x0005

Czech

cs-CZ

0x0405

Czech (Czech Republic)

da

0x0006

Danish

da-DK

0x0406

Danish (Denmark)

dv

0x0065

Divehi

dv-MV

0x0465

Divehi (Maldives)

nl

0x0013

Dutch

nl-BE

0x0813

Dutch (Belgium)

nl-NL

0x0413

Dutch (Netherlands)

en

0x0009

English

en-AU

0x0C09

English (Australia)

en-BZ

0x2809

English (Belize)

en-CA

0x1009

English (Canada)

en-029

0x2409

English (Caribbean)

en-IE

0x1809

English (Ireland)

en-JM

0x2009

English (Jamaica)

en-NZ

0x1409

English (New Zealand)

en-PH

0x3409

English (Philippines)

en-ZA

0x1C09

English (South Africa

en-TT

0x2C09

English (Trinidad and Tobago)

en-GB

0x0809

English (United Kingdom)

en-US

0x0409

English (United States)

en-ZW

0x3009

English (Zimbabwe)

et

0x0025

Estonian

et-EE

0x0425

Estonian (Estonia)

fo

0x0038

Faroese

fo-FO

0x0438

Faroese (Faroe Islands)

fa

0x0029

Farsi

fa-IR

0x0429

Farsi (Iran)

fi

0x000B

Finnish

fi-FI

0x040B

Finnish (Finland)

fr

0x000C

French

fr-BE

0x080C

French (Belgium)

fr-CA

0x0C0C

French (Canada)

fr-FR

0x040C

French (France)

fr-LU

0x140C

French (Luxembourg)

fr-MC

0x180C

French (Monaco)

fr-CH

0x100C

French (Switzerland)

gl

0x0056

Galician

gl-ES

0x0456

Galician (Spain)

ka

0x0037

Georgian

ka-GE

0x0437

Georgian (Georgia)

de

0x0007

German

de-AT

0x0C07

German (Austria)

de-DE

0x0407

German (Germany)

de-LI

0x1407

German (Liechtenstein)

de-LU

0x1007

German (Luxembourg)

de-CH

0x0807

German (Switzerland)

el

0x0008

Greek

el-GR

0x0408

Greek (Greece)

gu

0x0047

Gujarati

gu-IN

0x0447

Gujarati (India)

he

0x000D

Hebrew

he-IL

0x040D

Hebrew (Israel)

hi

0x0039

Hindi

hi-IN

0x0439

Hindi (India)

hu

0x000E

Hungarian

hu-HU

0x040E

Hungarian (Hungary)

is

0x000F

Icelandic

is-IS

0x040F

Icelandic (Iceland)

id

0x0021

Indonesian

id-ID

0x0421

Indonesian (Indonesia)

it

0x0010

Italian

it-IT

0x0410

Italian (Italy)

it-CH

0x0810

Italian (Switzerland)

ja

0x0011

Japanese

ja-JP

0x0411

Japanese (Japan)

kn

0x004B

Kannada

kn-IN

0x044B

Kannada (India)

kk

0x003F

Kazakh

kk-KZ

0x043F

Kazakh (Kazakhstan)

kok

0x0057

Konkani

kok-IN

0x0457

Konkani (India)

ko

0x0012

Korean

ko-KR

0x0412

Korean (Korea)

ky

0x0040

Kyrgyz

ky-KG

0x0440

Kyrgyz (Kyrgyzstan)

lv

0x0026

Latvian

lv-LV

0x0426

Latvian (Latvia)

lt

0x0027

Lithuanian

lt-LT

0x0427

Lithuanian (Lithuania)

mk

0x002F

Macedonian

mk-MK

0x042F

Macedonian (Macedonia, FYROM)

ms

0x003E

Malay

ms-BN

0x083E

Malay (Brunei Darussalam)

ms-MY

0x043E

Malay (Malaysia)

mr

0x004E

Marathi

mr-IN

0x044E

Marathi (India)

mn

0x0050

Mongolian

mn-MN

0x0450

Mongolian (Mongolia)

no

0x0014

Norwegian

nb-NO

0x0414

Norwegian (Bokmål, Norway)

nn-NO

0x0814

Norwegian (Nynorsk, Norway)

pl

0x0015

Polish

pl-PL

0x0415

Polish (Poland)

pt

0x0016

Portuguese

pt-BR

0x0416

Portuguese (Brazil)

pt-PT

0x0816

Portuguese (Portugal)

pa

0x0046

Punjabi

pa-IN

0x0446

Punjabi (India)

ro

0x0018

Romanian

ro-RO

0x0418

Romanian (Romania)

ru

0x0019

Russian

ru-RU

0x0419

Russian (Russia)

sa

0x004F

Sanskrit

sa-IN

0x044F

Sanskrit (India)

sr-Cyrl-CS

0x0C1A

Serbian (Serbia, Cyrillic)

sr-Latn-CS

0x081A

Serbian (Serbia, Latin)

sk

0x001B

Slovak

sk-SK

0x041B

Slovak (Slovakia)

sl

0x0024

Slovenian

sl-SI

0x0424

Slovenian (Slovenia)

es

0x000A

Spanish

es-AR

0x2C0A

Spanish (Argentina)

es-BO

0x400A

Spanish (Bolivia)

es-CL

0x340A

Spanish (Chile)

es-CO

0x240A

Spanish (Colombia)

es-CR

0x140A

Spanish (Costa Rica)

es-DO

0x1C0A

Spanish (Dominican Republic)

es-EC

0x300A

Spanish (Ecuador)

es-SV

0x440A

Spanish (El Salvador)

es-GT

0x100A

Spanish (Guatemala)

es-HN

0x480A

Spanish (Honduras)

es-MX

0x080A

Spanish (Mexico)

es-NI

0x4C0A

Spanish (Nicaragua)

es-PA

0x180A

Spanish (Panama)

es-PY

0x3C0A

Spanish (Paraguay)

es-PE

0x280A

Spanish (Peru)

es-PR

0x500A

Spanish (Puerto Rico)

es-ES

0x0C0A

Spanish (Spain)

es-ES_tradnl

0x040A

Spanish (Spain, Traditional Sort)

es-UY

0x380A

Spanish (Uruguay)

es-VE

0x200A

Spanish (Venezuela)

sw

0x0041

Swahili

sw-KE

0x0441

Swahili (Kenya)

sv

0x001D

Swedish

sv-FI

0x081D

Swedish (Finland)

sv-SE

0x041D

Swedish (Sweden)

syr

0x005A

Syriac

syr-SY

0x045A

Syriac (Syria)

ta

0x0049

Tamil

ta-IN

0x0449

Tamil (India)

tt

0x0044

Tatar

tt-RU

0x0444

Tatar (Russia)

te

0x004A

Telugu

te-IN

0x044A

Telugu (India)

th

0x001E

Thai

th-TH

0x041E

Thai (Thailand)

tr

0x001F

Turkish

tr-TR

0x041F

Turkish (Turkey)

uk

0x0022

Ukrainian

uk-UA

0x0422

Ukrainian (Ukraine)

ur

0x0020

Urdu

ur-PK

0x0420

Urdu (Pakistan)

uz

0x0043

Uzbek

uz-Cyrl-UZ

0x0843

Uzbek (Uzbekistan, Cyrillic)

uz-Latn-UZ

0x0443

Uzbek (Uzbekistan, Latin)

vi

0x002A

Vietnamese

vi-VN

0x042A

Vietnamese (Vietnam)

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

See Names associated with a CultureInfo object for a discussion of the relationship among these names.

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 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.

Note that 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. Additionally, the Name property of a CompareInfo object created for a neutral culture returns only the country and does not include the 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 the resources for the specific culture are not available in the system, the resources for the neutral culture are used. If the resources for the neutral culture are not available, the resources embedded in the main assembly are used. For more information on the resource fallback process, see Packaging and Deploying Resources.

The list of locales in the Windows API is slightly different from the list of cultures in the .NET Framework. If interoperability with Windows is required, for example, through the p/invoke mechanism, the application should use a specific culture that is defined for the operating system. Use of the specific culture ensures consistency with the equivalent Windows locale, which is identified with a locale identifier that is the same as LCID.

A DateTimeFormatInfo or a NumberFormatInfo can be created only for the invariant culture or for specific cultures, not for neutral cultures.

If DateTimeFormatInfo.Calendar is the TaiwanCalendar but the Thread.CurrentCulture is not "zh-TW", then DateTimeFormatInfo.NativeCalendarName, 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, spellings, etc., will probably change in the future. If your application needs to serialize using this data, as for the DateTime formatting and parsing functions, it should use the invariant culture or a specific format.

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. Also, as discussed below, an individual user can override cultural preferences. Applications should always obtain culture data at run time.

Caution noteCaution:

When saving data, your application should use the invariant culture, use a binary format, or use a specific culture-independent format. Data saved according to the current values associated with a particular culture, other than the invariant culture, might become unreadable or might change in meaning if that culture changes.

CultureInfo Object Serialization

When a CultureInfo object is serialized, all that is actually stored is Name and UseUserOverride. It is successfully de-serialized only in an environment where that Name has the same meaning. The following three examples show why this is not always the case:

  • If CultureTypes indicates CultureTypes.WindowsOnlyCultures, and if that culture was first introduced in Windows Vista, it is not possible to de-serialize it on Windows XP. Similarly, if the culture was first introduced in Windows XP Service Pack 2, it is not possible to de-serialize it for a Windows XP system on which the culture has not been installed.

  • If CultureTypes indicates CultureTypes.UserCustomCulture, and the computer on which it is de-serialized does not have this user custom culture installed, it is not possible to de-serialize it.

  • If CultureTypes indicates CultureTypes.ReplacementCultures, and the computer on which it is de-serialized does not have this replacement culture, it de-serializes to the same name, but not all of the same characteristics. For example, if "en-US" is a replacement culture on computer A, but not on computer B, and if a CultureInfo object referring to this culture is serialized on computer A and de-serialized on computer B, then none of the custom characteristics of the culture are transmitted. The culture de-serializes successfully, but with a different meaning.

Windows Locales

Starting in the .NET Framework version 2.0, the CultureInfo constructor supports using Windows locales, which are equivalent to cultures, to automatically generate cultures that do not exist in the .NET Framework. For more information, see Synthetic (Windows-Only) Cultures.

Control Panel Overrides

The user might choose to override some of the values associated with the current culture of Windows through the regional and language options portion of Control Panel. For example, the user might choose to display the date in a different format or to use a currency other than the default for the culture. In general, your applications should honor these user overrides.

If UseUserOverride is true and the specified culture matches the current culture of Windows, the CultureInfo uses those overrides, including user settings for the properties of the DateTimeFormatInfo instance returned by the DateTimeFormat property, and the properties of the NumberFormatInfo instance returned by the NumberFormat property. If the user settings are incompatible with the culture associated with the CultureInfo, for example, if the selected calendar is not one of the OptionalCalendars, the results of the methods and the values of the properties are undefined.

For cultures that use the euro, .NET Framework and Windows XP set the default currency as euro. However, older versions of Windows do not. Therefore, if the user of an older version of Windows has not changed the currency setting through the regional and language options portion of Control Panel, the currency might be incorrect. To use the .NET Framework default setting for the currency, the application should use a CultureInfo constructor overload that accepts a useUserOverride parameter and set it to false.

Alternate Sort Orders

The Spanish (Spain) culture uses two culture identifiers, 0x0C0A using the default international sort order, and 0x040A using the traditional sort order. If the CultureInfo is constructed using the "es-ES" culture name, the new CultureInfo uses the default international sort order. For the traditional sort order, the object is constructed using the name "es-ES_tradnl". For information on other cultures that have alternate sorts, see Comparing and Sorting Data for a Specific Culture.

Implemented Interfaces

This class implements the ICloneable interface to enable duplication of CultureInfo objects. It also implements IFormatProvider to supply formatting information to applications.

Cultures, Threads, and Application Domains

There are unique considerations when using a thread associated with a CultureInfo object. For more information about cultures and application domains, see Application Domains and Threads.

The following code example shows how to create a CultureInfo object for Spanish (Spain) with the international sort and another CultureInfo object with the traditional sort.

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

*/

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

The following code example determines the parent culture of each specific culture using the Chinese language.

NoteNote:

The example displays the zh-CHS and zh-CHT cultures with the 0x0004 and 0x7C04 culture identifiers, respectively. However, your Windows Vista applications should use the "zh-Hans" name instead of "zh-CHS" and the "zh-Hant" name instead of "zh-CHT". The "zh-Hans" and "zh-Hant" names represent the current standard, and should be used unless you have a reason for using the older names.

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-Hant Chinese (Traditional)
0x0804 zh-CN Chinese (People's Republic of China) 0x0004 zh-Hans Chinese (Simplified)
0x0C04 zh-HK Chinese (Hong Kong S.A.R.)           0x7C04 zh-Hant Chinese (Traditional)
0x1004 zh-SG Chinese (Singapore)                  0x0004 zh-Hans Chinese (Simplified)
0x1404 zh-MO Chinese (Macau S.A.R.)               0x7C04 zh-Hant Chinese (Traditional)

*/

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-Hant Chinese 
(Traditional)
0x0804 zh-CN Chinese (People's Republic of China) 0x0004 zh-Hans Chinese 
(Simplified)
0x0C04 zh-HK Chinese (Hong Kong S.A.R.)           0x7C04 zh-Hant Chinese 
(Traditional)
0x1004 zh-SG Chinese (Singapore)                  0x0004 zh-Hans Chinese 
(Simplified)
0x1404 zh-MO Chinese (Macau S.A.R.)               0x0004 zh-Hans Chinese 
(Simplified)
*/

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

Windows 98, Windows Server 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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.