当前位置: 首页>>代码示例>>C#>>正文


C# CultureInfo.CreateSpecificCulture方法代码示例

本文整理汇总了C#中System.Globalization.CultureInfo.CreateSpecificCulture方法的典型用法代码示例。如果您正苦于以下问题:C# CultureInfo.CreateSpecificCulture方法的具体用法?C# CultureInfo.CreateSpecificCulture怎么用?C# CultureInfo.CreateSpecificCulture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Globalization.CultureInfo的用法示例。


在下文中一共展示了CultureInfo.CreateSpecificCulture方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

//引入命名空间
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;

public class Example
{
   public static void Main()
   {
      // Display the header.
      Console.WriteLine("{0,-53}{1}", "CULTURE", "SPECIFIC CULTURE");

      // Get each neutral culture in the .NET Framework.
      CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.NeutralCultures);
      // Sort the returned array by name.
      Array.Sort<CultureInfo>(cultures, new NamePropertyComparer<CultureInfo>());
      
      // Determine the specific culture associated with each neutral culture.
      foreach (var culture in cultures) 
      {
         Console.Write("{0,-12} {1,-40}", culture.Name, culture.EnglishName);
         try {
            Console.WriteLine("{0}", CultureInfo.CreateSpecificCulture(culture.Name).Name);
         }   
         catch (ArgumentException) {
            Console.WriteLine("(no associated specific culture)");
         }
      } 
   }
}

public class NamePropertyComparer<T> : IComparer<T>
{
   public int Compare(T x, T y) 
   {
      if (x == null)
         if (y == null)
            return 0;
         else
            return -1;

      PropertyInfo pX = x.GetType().GetProperty("Name");
      PropertyInfo pY = y.GetType().GetProperty("Name");             
      return String.Compare((string) pX.GetValue(x, null), (string) pY.GetValue(y, null));
   }
}
// The example displays the following output on a Windows system.  This output has been cropped for brevity.
//    CULTURE                                              SPECIFIC CULTURE
//                 Invariant Language (Invariant Country)  
//    aa           Afar                                    aa-ET
//    af           Afrikaans                               af-ZA
//    agq          Aghem                                   agq-CM
//    ak           Akan                                    ak-GH
//    am           Amharic                                 am-ET
//    ar           Arabic                                  ar-SA
//    arn          Mapudungun                              arn-CL
//    as           Assamese                                as-IN
//    asa          Asu                                     asa-TZ
//    ast          Asturian                                ast-ES
//    az           Azerbaijani                             az-Latn-AZ
//    az-Cyrl      Azerbaijani (Cyrillic)                  az-Cyrl-AZ
//    az-Latn      Azerbaijani (Latin)                     az-Latn-AZ
//    ba           Bashkir                                 ba-RU
//    bas          Basaa                                   bas-CM
//    be           Belarusian                              be-BY
//    bem          Bemba                                   bem-ZM
//    bez          Bena                                    bez-TZ
//    bg           Bulgarian                               bg-BG
//    bin          Edo                                     bin-NG
//    bm           Bamanankan                              bm-Latn-ML
//    bm-Latn      Bamanankan (Latin)                      bm-Latn-ML
//    bn           Bangla                                  bn-BD
//    bo           Tibetan                                 bo-CN
//    br           Breton                                  br-FR
//    brx          Bodo                                    brx-IN
//    bs           Bosnian                                 bs-Latn-BA
//    bs-Cyrl      Bosnian (Cyrillic)                      bs-Cyrl-BA
//    bs-Latn      Bosnian (Latin)                         bs-Latn-BA
//    byn          Blin                                    byn-ER
//    ca           Catalan                                 ca-ES
//    ce           Chechen                                 ce-RU
//    cgg          Chiga                                   cgg-UG
//    chr          Cherokee                                chr-Cher-US
//    chr-Cher     Cherokee                                chr-Cher-US
//    co           Corsican                                co-FR
//    cs           Czech                                   cs-CZ
//    cu           Church Slavic                           cu-RU
//    cy           Welsh                                   cy-GB
//    da           Danish                                  da-DK
//    dav          Taita                                   dav-KE
//    de           German                                  de-DE
//    dje          Zarma                                   dje-NE
//    dsb          Lower Sorbian                           dsb-DE
//    dua          Duala                                   dua-CM
//    dv           Divehi                                  dv-MV
//    ...
//    ta           Tamil                                   ta-IN
//    te           Telugu                                  te-IN
//    teo          Teso                                    teo-UG
//    tg           Tajik                                   tg-Cyrl-TJ
//    tg-Cyrl      Tajik (Cyrillic)                        tg-Cyrl-TJ
//    th           Thai                                    th-TH
//    ti           Tigrinya                                ti-ER
//    tig          Tigre                                   tig-ER
//    tk           Turkmen                                 tk-TM
//    tn           Setswana                                tn-ZA
//    to           Tongan                                  to-TO
//    tr           Turkish                                 tr-TR
//    ts           Tsonga                                  ts-ZA
//    tt           Tatar                                   tt-RU
//    twq          Tasawaq                                 twq-NE
//    tzm          Central Atlas Tamazight                 tzm-Latn-DZ
//    tzm-Arab     Central Atlas Tamazight (Arabic)        tzm-Arab-MA
//    tzm-Latn     Central Atlas Tamazight (Latin)         tzm-Latn-DZ
//    tzm-Tfng     Central Atlas Tamazight (Tifinagh)      tzm-Tfng-MA
//    ug           Uyghur                                  ug-CN
//    uk           Ukrainian                               uk-UA
//    ur           Urdu                                    ur-PK
//    uz           Uzbek                                   uz-Latn-UZ
//    uz-Arab      Uzbek (Perso-Arabic)                    uz-Arab-AF
//    uz-Cyrl      Uzbek (Cyrillic)                        uz-Cyrl-UZ
//    uz-Latn      Uzbek (Latin)                           uz-Latn-UZ
//    vai          Vai                                     vai-Vaii-LR
//    vai-Latn     Vai (Latin)                             vai-Latn-LR
//    vai-Vaii     Vai (Vai)                               vai-Vaii-LR
//    ve           Venda                                   ve-ZA
//    vi           Vietnamese                              vi-VN
//    vo           Volapük                                 vo-001
//    vun          Vunjo                                   vun-TZ
//    wae          Walser                                  wae-CH
//    wal          Wolaytta                                wal-ET
//    wo           Wolof                                   wo-SN
//    xh           isiXhosa                                xh-ZA
//    xog          Soga                                    xog-UG
//    yav          Yangben                                 yav-CM
//    yi           Yiddish                                 yi-001
//    yo           Yoruba                                  yo-NG
//    zgh          Standard Moroccan Tamazight             zgh-Tfng-MA
//    zgh-Tfng     Standard Moroccan Tamazight (Tifinagh)  zgh-Tfng-MA
//    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
// The example displays output like the following on a Unix-based system. The output has been cropped for brevity.
//    CULTURE                                              SPECIFIC CULTURE
//                 Invariant Language (Invariant Country)
//    af           Afrikaans                               af-ZA
//    agq          Aghem                                   agq-CM
//    ak           Akan                                    ak-GH
//    am           Amharic                                 am-ET
//    ar           Arabic                                  ar-SA
//    as           Assamese                                as-IN
//    asa          Asu                                     asa-TZ
//    ast          Asturian                                ast-ES
//    az           Azerbaijani                             az-Latn-AZ
//    az-Cyrl      Azerbaijani                             az-Cyrl-AZ
//    az-Latn      Azerbaijani                             az-Latn-AZ
//    bas          Basaa                                   bas-CM
//    be           Belarusian                              be-BY
//    bem          Bemba                                   bem-ZM
//    bez          Bena                                    bez-TZ
//    bg           Bulgarian                               bg-BG
//    bm           Bambara                                 bm-Latn-ML
//    bn           Bangla                                  bn-BD
//    bo           Tibetan                                 bo-CN
//    br           Breton                                  br-FR
//    brx          Bodo                                    brx-IN
//    bs           Bosnian                                 bs-Latn-BA
//    bs-Cyrl      Bosnian                                 bs-Cyrl-BA
//    bs-Latn      Bosnian                                 bs-Latn-BA
//    ca           Catalan                                 ca-ES
//    ccp          Chakma
//    ce           Chechen                                 ce-RU
//    cgg          Chiga                                   cgg-UG
//    chr          Cherokee                                chr-Cher-US
//    ckb          Central Kurdish
//    cs           Czech                                   cs-CZ
//    cy           Welsh                                   cy-GB
//    da           Danish                                  da-DK
//    dav          Taita                                   dav-KE
//    de           German                                  de-DE
//    dje          Zarma                                   dje-NE
//    dsb          Lower Sorbian                           dsb-DE
//    dua          Duala                                   dua-CM
//    ...
//    ta           Tamil                                   ta-IN
//    te           Telugu                                  te-IN
//    teo          Teso                                    teo-UG
//    tg           Tajik                                   tg-Cyrl-TJ
//    th           Thai                                    th-TH
//    ti           Tigrinya                                ti-ER
//    to           Tongan                                  to-TO
//    tr           Turkish                                 tr-TR
//    tt           Tatar                                   tt-RU
//    twq          Tasawaq                                 twq-NE
//    tzm          Central Atlas Tamazight                 tzm-Latn-DZ
//    ug           Uyghur                                  ug-CN
//    uk           Ukrainian                               uk-UA
//    ur           Urdu                                    ur-PK
//    uz           Uzbek                                   uz-Latn-UZ
//    uz-Arab      Uzbek                                   uz-Arab-AF
//    uz-Cyrl      Uzbek                                   uz-Cyrl-UZ
//    uz-Latn      Uzbek                                   uz-Latn-UZ
//    vai          Vai                                     vai-Vaii-LR
//    vai-Latn     Vai                                     vai-Latn-LR
//    vai-Vaii     Vai                                     vai-Vaii-LR
//    vi           Vietnamese                              vi-VN
//    vun          Vunjo                                   vun-TZ
//    wae          Walser                                  wae-CH
//    wo           Wolof                                   wo-SN
//    xog          Soga                                    xog-UG
//    yav          Yangben                                 yav-CM
//    yi           Yiddish                                 yi-001
//    yo           Yoruba                                  yo-NG
//    yue          Cantonese                               yue-HK
//    yue-Hans     Cantonese
//    yue-Hant     Cantonese
//    zgh          Standard Moroccan Tamazight             zgh-Tfng-MA
//    zh           Chinese                                 zh-CN
//    zh-Hans      Chinese                                 zh-CN
//    zh-Hant      Chinese                                 zh-HK
//    zu           Zulu                                    zu-ZA
开发者ID:.NET开发者,项目名称:System.Globalization,代码行数:225,代码来源:CultureInfo.CreateSpecificCulture

示例2: Main

//引入命名空间
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Threading;
using System.Globalization;

public class MainClass
{
    public static void Main()
    {
        decimal money = 1250.75m;
        string[] cultures = { "en-US", "en-GB", "ja", "ar" };
        Console.OutputEncoding = Encoding.UTF8;
        foreach (string culture in cultures)
        {
            CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(culture);
            Console.WriteLine("{0} = {1}", cultureInfo.DisplayName,money.ToString("C", cultureInfo));
        }
    }
}
开发者ID:C#程序员,项目名称:System.Globalization,代码行数:25,代码来源:CultureInfo.CreateSpecificCulture


注:本文中的System.Globalization.CultureInfo.CreateSpecificCulture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。