Export (0) Print
Expand All

CultureInfo.CreateSpecificCulture Method

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

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

'Declaration
Public Shared Function CreateSpecificCulture ( _
	name As String _
) As CultureInfo

Parameters

name
Type: System.String

A predefined CultureInfo name or the name of an existing CultureInfo object. name is not case-sensitive.

Return Value

Type: System.Globalization.CultureInfo
A CultureInfo object that represents:
The invariant culture, if name is an empty string ("").
-or-
The specific culture associated with name, if name is a neutral culture.
-or-
The culture specified by name, if name is already a specific culture.

ExceptionCondition
CultureNotFoundException

name is not a valid culture name.

-or-

The culture specified by name does not have a specific culture associated with it.

NullReferenceException

name is null.

For a list of predefined culture names, see the National Language Support (NLS) API Reference at the Go Global Developer Center.

Cultures are grouped into three sets: the invariant culture, the neutral cultures, and the specific cultures. For more information, see the description of the CultureInfo class.

If the culture identifier of the specific culture returned by this method matches the culture identifier of the current Windows culture, this method creates a CultureInfo object that uses the Windows culture overrides. The overrides include user settings for the properties of the DateTimeFormatInfo object returned by the DateTimeFormat property and the NumberFormatInfo object returned by the NumberFormat property.

Although the CreateSpecificCulture method name includes the term "Specific", remember that culture data can change between versions, or due to custom cultures, or because of user overrides. Use the invariant culture or binary or fixed forms for saving data.

Notes to Callers

The .NET Framework 3.5 and earlier versions throw an ArgumentException if name is not a valid culture name. Starting with the .NET Framework 4, this method throws a CultureNotFoundException.

The following example retrieves an array of CultureInfo objects that represent neutral cultures from the GetCultures method and sorts the array. When it iterates the elements in the array, it passes the name of each neutral culture to the CreateSpecificCulture method and displays the name of the specific culture returned by the method.

NoteNote

The example uses the zh-CHS and zh-CHT culture names. However, applications that target Windows Vista and later should use zh-Hans instead of zh-CHS and zh-Hant instead of zh-CHT. zh-Hans and zh-Hant represent the current standard and should be used unless you have a reason for using the older names.

Note also that the results of the example may differ on an installation of Taiwanese Windows, where the input of a Chinese (Traditional) neutral culture (zh, zh-CHT, or zh-Hant) will return zh-TW.

Imports System.Collections.Generic
Imports System.Globalization
Imports System.Reflection

Public Class Example
   Public Shared Sub Main()
      ' Display the header.
      Console.WriteLine("{0,-53}{1}", "CULTURE", "SPECIFIC CULTURE")

      ' Get each neutral culture in the .NET Framework. 
      Dim cultures() As CultureInfo = CultureInfo.GetCultures(CultureTypes.NeutralCultures)
      ' Sort the returned array by name.
      Array.Sort(Of CultureInfo)(cultures, New NamePropertyComparer(Of CultureInfo)())

      ' Determine the specific culture associated with each neutral culture. 
      For Each culture As CultureInfo In cultures
         Console.Write("{0,-12} {1,-40}", culture.Name, culture.EnglishName)
         Try
            Console.WriteLine("{0}", CultureInfo.CreateSpecificCulture(culture.Name).Name)
         Catch e As ArgumentException
            Console.WriteLine("(no associated specific culture)")
         End Try 
      Next  
   End Sub 
End Class 

Public Class NamePropertyComparer(Of T) : Implements IComparer(Of T)
   Public Function Compare(x As T, y As T) As Integer _
                   Implements IComparer(Of T).Compare
      If x Is Nothing Then 
         If y Is Nothing Then 
            Return 0
         Else 
            Return -1
         End If 
      End If  
      Dim pX As PropertyInfo = x.GetType().GetProperty("Name")
      Dim pY As PropertyInfo = y.GetType().GetProperty("Name")             
      Return String.Compare(CStr(pX.GetValue(x, Nothing)), CStr(pY.GetValue(y, Nothing)))
   End Function 
End Class 
' The example displays the following output.  This output has been cropped for brevity. 
'    CULTURE                                              SPECIFIC CULTURE 
'                 Invariant Language (Invariant Country)   
'    af           Afrikaans                               af-ZA 
'    am           Amharic                                 am-ET 
'    ar           Arabic                                  ar-SA 
'    arn          Mapudungun                              arn-CL 
'    as           Assamese                                as-IN 
'    az           Azerbaijani                             az-Latn-AZ 
'    az-Cyrl      Azerbaijani (Cyrillic)                  az-Cyrl-AZ 
'    az-Latn      Azerbaijani (Latin)                     az-Latn-AZ 
'    ba           Bashkir                                 ba-RU 
'    be           Belarusian                              be-BY 
'    bg           Bulgarian                               bg-BG 
'    bn           Bengali                                 bn-IN 
'    bo           Tibetan                                 bo-CN 
'    br           Breton                                  br-FR 
'    bs           Bosnian                                 bs-Latn-BA 
'    bs-Cyrl      Bosnian (Cyrillic)                      bs-Cyrl-BA 
'    bs-Latn      Bosnian (Latin)                         bs-Latn-BA 
'    ca           Catalan                                 ca-ES 
'    co           Corsican                                co-FR 
'    cs           Czech                                   cs-CZ 
'    cy           Welsh                                   cy-GB 
'    da           Danish                                  da-DK 
'    de           German                                  de-DE 
'    dsb          Lower Sorbian                           dsb-DE 
'    dv           Divehi                                  dv-MV 
'    ... 
'    ta           Tamil                                   ta-IN 
'    te           Telugu                                  te-IN 
'    tg           Tajik                                   tg-Cyrl-TJ 
'    tg-Cyrl      Tajik (Cyrillic)                        tg-Cyrl-TJ 
'    th           Thai                                    th-TH 
'    tk           Turkmen                                 tk-TM 
'    tn           Setswana                                tn-ZA 
'    tr           Turkish                                 tr-TR 
'    tt           Tatar                                   tt-RU 
'    tzm          Tamazight                               tzm-Latn-DZ 
'    tzm-Latn     Tamazight (Latin)                       tzm-Latn-DZ 
'    ug           Uyghur                                  ug-CN 
'    uk           Ukrainian                               uk-UA 
'    ur           Urdu                                    ur-PK 
'    uz           Uzbek                                   uz-Latn-UZ 
'    uz-Cyrl      Uzbek (Cyrillic)                        uz-Cyrl-UZ 
'    uz-Latn      Uzbek (Latin)                           uz-Latn-UZ 
'    vi           Vietnamese                              vi-VN 
'    wo           Wolof                                   wo-SN 
'    xh           isiXhosa                                xh-ZA 
'    yo           Yoruba                                  yo-NG 
'    zh           Chinese                                 zh-CN 
'    zh-CHS       Chinese (Simplified) Legacy             zh-CN 
'    zh-CHT       Chinese (Traditional) Legacy            zh-HK 
'    zh-Hans      Chinese (Simplified)                    zh-CN 
'    zh-Hant      Chinese (Traditional)                   zh-HK 
'    zu           isiZulu                                 zu-ZA

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft