从ISO货币符号获取NativeEnglishName不依赖于当前的文化登录的用户 [英] Get NativeEnglishName from iso currency symbol without dependency to the current culture of logged in user
问题描述
我有什么是currencyIso code欧元。这种属性也可以在发现
what I have is the currencyIsoCode "EUR". This Property can also be found in the
RegionInfo类=> ri.ISOCurrencySymbol。但RegionInfo类依赖于登录用户的电流。
RegionInfo class => ri.ISOCurrencySymbol. But the RegionInfo class depends on the current logged in user.
我要的是得到NativeEnglishName像欧元,甚至当用户从EN-DE,EN-US,CN-CN等..
What I want is to get the NativeEnglishName like "Euro" even when the user is from en-De, en-Us, cn-CN etc...
我怎么能这样做?
推荐答案
尴尬的问题,有没有简单的方法来遍历可用RegionInfo。你不得不遍历所有可用的特定文化,打造属于RegionInfo比较。这code能够完成任务:
Awkward problem, there is no easy way to iterate the available RegionInfo. You'd have to iterate all available specific cultures and create their RegionInfo to compare. This code gets the job done:
public static string GetEnglishCurrencyName(string iso) {
foreach (var c in CultureInfo.GetCultures(CultureTypes.SpecificCultures)) {
var reg = new RegionInfo(c.LCID);
if (string.Compare(iso, reg.ISOCurrencySymbol, true) == 0)
return reg.CurrencyEnglishName;
}
throw new ArgumentException();
}
要小心,这会产生大量的垃圾。如果你这样做的时候,一定要缓存区域的信息在字典<>第一
Beware that this generates a lot of garbage. If you do this often, be sure to cache the region info in a Dictionary<> first.
这篇关于从ISO货币符号获取NativeEnglishName不依赖于当前的文化登录的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!