Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

CultureInfo.CreateSpecificCulture Method

Creates a CultureInfo that represents the specific culture that is associated with the specified name.

[Visual Basic]
Public Shared Function CreateSpecificCulture( _
   ByVal name As String _
) As CultureInfo
[C#]
public static CultureInfo CreateSpecificCulture(
 string name
);
[C++]
public: static CultureInfo* CreateSpecificCulture(
 String* name
);
[JScript]
public static function CreateSpecificCulture(
   name : String
) : CultureInfo;

Parameters

name
A predefined CultureInfo name or the name of an existing CultureInfo.

Return Value

A CultureInfo that represents the invariant culture, if name is "" (invariant culture).

-or-

A CultureInfo that represents the default specific culture associated with name, if name is a neutral culture.

-or-

A CultureInfo that represents name, if name is already a specific culture.

Exceptions

Exception Type Condition
ArgumentNullException name is a null reference (Nothing in Visual Basic).
ArgumentException name is not a valid culture name.

-or-

The culture specified by name does not have a specific culture associated with it. For example: "zh-CHS" or "zh-CHT".

Remarks

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

The invariant culture is culture-insensitive. You can specify the invariant culture by name using an empty string ("") or by its culture identifier 0x007F. InvariantCulture retrieves an instance of the invariant culture. It is associated with the English language but not with any country/region. It can be used in almost any method in the Globalization namespace that requires a culture. If a security decision depends on a string comparison or a case-change operation, use the InvariantCulture to ensure that the behavior will be consistent regardless of the culture settings of the system. However, the invariant culture must be used only by processes that require culture-independent results, such as system services; otherwise, it produces results that might be linguistically incorrect or culturally inappropriate.

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-CHS" (Simplified Chinese) and "zh-CHT" (Traditional Chinese) are neutral cultures.

The cultures have a hierarchy, such that the parent of a specific culture is a neutral culture and the parent of a neutral culture is the InvariantCulture. The Parent property returns the neutral culture associated with a specific culture.

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 Resource Fallback Process.

The list of cultures in the Windows API is slightly different from the list of cultures in the .NET Framework. For example, the neutral culture zh-CHT "Chinese (Traditional)" with culture identifier 0x7C04 is not available in the Windows API. If interoperability with Windows is required (for example, through the p/invoke mechanism), use a specific culture that is defined in the .NET Framework. This will ensure consistency with the equivalent Windows locale, which is identified with the same LCID.

Example

[Visual Basic, C#, C++] The following code example shows the results of CreateSpecificCulture with different culture types.

[Visual Basic] 
Imports System
Imports System.Globalization

Public Class SamplesCultureInfo

   Public Shared Sub Main()

      ' Prints the header.
      Console.WriteLine("CULTURE                                              SPECIFIC CULTURE")

      ' Determines the specific culture associated with each culture in the .NET Framework.
      Dim ci As CultureInfo
      For Each ci In  CultureInfo.GetCultures(CultureTypes.AllCultures)
         Console.Write("{0,-12} {1,-40}", ci.Name, ci.EnglishName)
         Try
            Console.WriteLine("{0}", CultureInfo.CreateSpecificCulture(ci.Name).Name)
         Catch e As ArgumentException
            Console.WriteLine("(no associated specific culture)")
         End Try
      Next ci

   End Sub 'Main

End Class 'SamplesCultureInfo 


'This code produces the following output.  This output has been cropped for brevity.
'
'CULTURE                                              SPECIFIC CULTURE
'ar           Arabic                                  ar-SA
'ar-SA        Arabic (Saudi Arabia)                   ar-SA
'ar-IQ        Arabic (Iraq)                           ar-IQ
'ar-EG        Arabic (Egypt)                          ar-EG
'ar-LY        Arabic (Libya)                          ar-LY
'ar-DZ        Arabic (Algeria)                        ar-DZ
'ar-MA        Arabic (Morocco)                        ar-MA
'ar-TN        Arabic (Tunisia)                        ar-TN
'ar-OM        Arabic (Oman)                           ar-OM
'ar-YE        Arabic (Yemen)                          ar-YE
'ar-SY        Arabic (Syria)                          ar-SY
'ar-JO        Arabic (Jordan)                         ar-JO
'ar-LB        Arabic (Lebanon)                        ar-LB
'ar-KW        Arabic (Kuwait)                         ar-KW
'ar-AE        Arabic (U.A.E.)                         ar-AE
'ar-BH        Arabic (Bahrain)                        ar-BH
'ar-QA        Arabic (Qatar)                          ar-QA
'bg           Bulgarian                               bg-BG
'bg-BG        Bulgarian (Bulgaria)                    bg-BG
'ca           Catalan                                 ca-ES
'ca-ES        Catalan (Catalan)                       ca-ES
'zh-CHS       Chinese (Simplified)                    (no associated specific culture)
'zh-TW        Chinese (Taiwan)                        zh-TW
'zh-CN        Chinese (People's Republic of China)    zh-CN
'zh-HK        Chinese (Hong Kong S.A.R.)              zh-HK
'zh-SG        Chinese (Singapore)                     zh-SG
'zh-MO        Chinese (Macau S.A.R.)                  zh-MO
'zh-CHT       Chinese (Traditional)                   (no associated specific culture)
'cs           Czech                                   cs-CZ
'cs-CZ        Czech (Czech Republic)                  cs-CZ
'da           Danish                                  da-DK
'da-DK        Danish (Denmark)                        da-DK


[C#] 
using System;
using System.Globalization;

public class SamplesCultureInfo  {

   public static void Main()  {

      // Prints the header.
      Console.WriteLine( "CULTURE                                              SPECIFIC CULTURE" );

      // Determines the specific culture associated with each culture in the .NET Framework.
      foreach ( CultureInfo ci in CultureInfo.GetCultures( CultureTypes.AllCultures ) )  {
         Console.Write( "{0,-12} {1,-40}", ci.Name, ci.EnglishName );
         try  {
            Console.WriteLine( "{0}", CultureInfo.CreateSpecificCulture( ci.Name ).Name );
         }
         catch  {
            Console.WriteLine( "(no associated specific culture)" );
         }
      }

   }

}


/*
This code produces the following output.  This output has been cropped for brevity.

CULTURE                                              SPECIFIC CULTURE
ar           Arabic                                  ar-SA
ar-SA        Arabic (Saudi Arabia)                   ar-SA
ar-IQ        Arabic (Iraq)                           ar-IQ
ar-EG        Arabic (Egypt)                          ar-EG
ar-LY        Arabic (Libya)                          ar-LY
ar-DZ        Arabic (Algeria)                        ar-DZ
ar-MA        Arabic (Morocco)                        ar-MA
ar-TN        Arabic (Tunisia)                        ar-TN
ar-OM        Arabic (Oman)                           ar-OM
ar-YE        Arabic (Yemen)                          ar-YE
ar-SY        Arabic (Syria)                          ar-SY
ar-JO        Arabic (Jordan)                         ar-JO
ar-LB        Arabic (Lebanon)                        ar-LB
ar-KW        Arabic (Kuwait)                         ar-KW
ar-AE        Arabic (U.A.E.)                         ar-AE
ar-BH        Arabic (Bahrain)                        ar-BH
ar-QA        Arabic (Qatar)                          ar-QA
bg           Bulgarian                               bg-BG
bg-BG        Bulgarian (Bulgaria)                    bg-BG
ca           Catalan                                 ca-ES
ca-ES        Catalan (Catalan)                       ca-ES
zh-CHS       Chinese (Simplified)                    (no associated specific culture)
zh-TW        Chinese (Taiwan)                        zh-TW
zh-CN        Chinese (People's Republic of China)    zh-CN
zh-HK        Chinese (Hong Kong S.A.R.)              zh-HK
zh-SG        Chinese (Singapore)                     zh-SG
zh-MO        Chinese (Macau S.A.R.)                  zh-MO
zh-CHT       Chinese (Traditional)                   (no associated specific culture)
cs           Czech                                   cs-CZ
cs-CZ        Czech (Czech Republic)                  cs-CZ
da           Danish                                  da-DK
da-DK        Danish (Denmark)                        da-DK

*/

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;

int main() {
   // Prints the header.
   Console::WriteLine(S"CULTURE                                              SPECIFIC CULTURE");

   // Determines the specific culture associated with each culture in the .NET Framework.
   System::Collections::IEnumerator* myEnum = CultureInfo::GetCultures(CultureTypes::AllCultures)->GetEnumerator();
   while (myEnum->MoveNext()) {
      CultureInfo* ci = dynamic_cast<CultureInfo*>(myEnum->Current);
      Console::Write(S"{0, -12} {1, -40}", ci->Name, ci->EnglishName);
      try {
         Console::WriteLine(S"{0}", CultureInfo::CreateSpecificCulture(ci->Name)->Name);
      } catch (Exception*) {
         Console::WriteLine(S"(no associated specific culture)");
      }
   }
}

/*
This code produces the following output.  This output has been cropped for brevity.

CULTURE                                              SPECIFIC CULTURE
ar           Arabic                                  ar-SA
ar-SA        Arabic (Saudi Arabia)                   ar-SA
ar-IQ        Arabic (Iraq)                           ar-IQ
ar-EG        Arabic (Egypt)                          ar-EG
ar-LY        Arabic (Libya)                          ar-LY
ar-DZ        Arabic (Algeria)                        ar-DZ
ar-MA        Arabic (Morocco)                        ar-MA
ar-TN        Arabic (Tunisia)                        ar-TN
ar-OM        Arabic (Oman)                           ar-OM
ar-YE        Arabic (Yemen)                          ar-YE
ar-SY        Arabic (Syria)                          ar-SY
ar-JO        Arabic (Jordan)                         ar-JO
ar-LB        Arabic (Lebanon)                        ar-LB
ar-KW        Arabic (Kuwait)                         ar-KW
ar-AE        Arabic (U.A.E.)                         ar-AE
ar-BH        Arabic (Bahrain)                        ar-BH
ar-QA        Arabic (Qatar)                          ar-QA
bg           Bulgarian                               bg-BG
bg-BG        Bulgarian (Bulgaria)                    bg-BG
ca           Catalan                                 ca-ES
ca-ES        Catalan (Catalan)                       ca-ES
zh-CHS       Chinese (Simplified)                    (no associated specific culture)
zh-TW        Chinese (Taiwan)                        zh-TW
zh-CN        Chinese (People's Republic of China)    zh-CN
zh-HK        Chinese (Hong Kong S.A.R.)              zh-HK
zh-SG        Chinese (Singapore)                     zh-SG
zh-MO        Chinese (Macau S.A.R.)                  zh-MO
zh-CHT       Chinese (Traditional)                   (no associated specific culture)
cs           Czech                                   cs-CZ
cs-CZ        Czech (Czech Republic)                  cs-CZ
da           Danish                                  da-DK
da-DK        Danish (Denmark)                        da-DK

*/

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

CultureInfo Class | CultureInfo Members | System.Globalization Namespace | CultureInfo | Parent

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.