2014-10-01 104 views
0

我试图将ISO货币代码转换为货币符号,但RegionInfo的返回值似乎已交换。这里是我的代码:RegionInfo.ISOCurrencySymbol返回CurrencyEnglishName而不是

foreach (CultureInfo nfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures)) 
{ 
    RegionInfo region = new RegionInfo(nfo.LCID); 
    Log("ISO: " + region.ISOCurrencySymbol); 
    Log("Symbol: " + region.CurrencySymbol); 
} 

编辑:Log() - 方法只是打印一个字符串出于调试目的。

对于每种语言,我得到这样的:

  • ISO:美元(应为 “USD”)
  • 符号:USD(应为 “$”)

怎么可能这发生了,我怎么修复它?

Edit2:测试了一些:RegionInfo中的大多数字段似乎都是空的,.CurrencyNativeName引发NotImplementedException。这里发生了什么?

+0

什么是'Log'功能吗? – Arion 2014-10-01 11:25:52

+0

这只是一个调试日志 – Bob 2014-10-01 11:28:09

+1

它在我的机器上打印'USD'和'$'。你确定吗?你的环境是什么? (.NET Framework版本或其他..) – 2014-10-01 12:59:59

回答

0

我知道它的晚,但这里对我的作品

 public List<string> getCurrencyCode() 
     { 
      List<string> CountryList = new List<string>(); 
      List<string> CurrencyList = new List<string>(); 
      CultureInfo[] getCultureInfo = CultureInfo.GetCultures(CultureTypes.SpecificCultures); 

      foreach (CultureInfo getCulture in getCultureInfo) 
      { 
       RegionInfo ri = new RegionInfo(getCulture.LCID); 
       //Region includes country name and currency symbols 
       //make sure no repeats 
       if (!(CountryList.Contains(ri.EnglishName))) 
       { 
        CountryList.Add(ri.EnglishName); 
        CurrencyList.Add(ri.ISOCurrencySymbol);      
       } 
      } 
      return CurrencyList; 
     }