RegionInfo.ISOCurrencySymbol returns CurrencyEnglishName ins

本文关键字:ins CurrencyEnglishName returns ISOCurrencySymbol RegionInfo | 更新日期: 2023-09-27 18:25:16

我试图将ISO货币代码转换为货币符号,但RegionInfo的返回值似乎被交换了。这是我的代码:

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

Edit:Log()-方法只是为了调试目的而打印一个字符串。

对于每种语言,我都会得到这样的东西:

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

这怎么会发生,我该怎么解决?

第2版:测试了更多:RegionInfo中的大多数字段似乎都是空的。CurrencyNativeName抛出了一个NotImplementedException。这到底是怎么回事?

RegionInfo.ISOCurrencySymbol returns CurrencyEnglishName ins

我知道它很晚了,但这里对我有效

        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;
        }