2011-01-10 21 views
2

我想爲我的應用程序創建一個貨幣組合框(下拉列表)控件,並且給定貨幣作爲RegionInfo對象內的屬性存在。如果任何人有把它們放入數組的方式,我會漫步。c#currency combobox

乾杯,

理查德

回答

7

像這樣:

CultureInfo.GetCultures(CultureTypes.SpecificCultures) 
      .Select(c => new RegionInfo(c.LCID).CurrencySymbol) 
      .Distinct() 

在我的(Windows 7)中的機器,這將產生

ر.س.‏ 
лв. 
€ 
NT$ 
Kč 
kr. 
$ 
₪ 
Ft 
¥ 
₩ 
kr 
zł 
R$ 
fr. 
lei 
р. 
kn 
Lek 
฿ 
TL 
Rs 
Rp 
₴ 
Ls 
Lt 
т.р. 
ريال 
₫ 
դր. 
man. 
ден. 
R 
Lari 
रु 
RM 
Т 
сом 
S 
m. 
so'm 
টা 
ਰੁ 
રૂ 
ଟ 
ரூ 
రూ 
ರೂ 
ക 
ট 
₮ 
£ 
៛ 
₭ 
ل.س.‏ 
රු. 
ETB 
؋ 
PhP 
ރ. 
N 
$b 
һ. 
с. 
Q 
RWF 
XOF 
د.ع.‏ 
Fr. 
Din. 
ман. 
сўм 
৳ 
DZD 
ج.م.‏ 
HK$ 
Дин. 
S/. 
د.ل.‏ 
KM 
د.ج.‏ 
MOP 
CHF 
₡ 
د.م.‏ 
B/. 
د.ت.‏ 
RD$ 
КМ 
ر.ع.‏ 
J$ 
Bs. F. 
ر.ي.‏ 
BZ$ 
د.ا.‏ 
TT$ 
ل.ل.‏ 
Z$ 
د.ك.‏ 
Php 
د.إ.‏ 
$U 
د.ب.‏ 
Gs 
ر.ق.‏ 
Rs. 
L. 
C$ 
0

對於我們這些在.NET 2 (沒有選擇內部數組),並打破了一些發生在SLak的優秀答案中的東西:

(現在使用GetDistinctValues從http://weblogs.asp.net/gunnarpeipman/archive/2008/05/15/getting-distinct-values-from-arrays.aspx因爲在.net 3.5沒有明顯)

 CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures); 
     List<string> CountryCodes = new List<string>(); 
     foreach (CultureInfo ci in cultures) 
     { 
      RegionInfo ri = new RegionInfo(ci.LCID); 
      CountryCodes.Add(ri.ISOCurrencySymbol); 
     } 
     string [] CountryCodeArray = GetDistinctValues(CountryCodes.ToArray()); 

public string[] GetDistinctValues(string[] array) 
{ 
    List<string> list = new List<string>(); 

    for (int i = 0; i < array.Length; i++) 
    { 
     if (list.Contains(array[i])) 
      continue; 
     list.Add(array[i]); 
    } 
    return list.ToArray(); 
} 
+0

你可以叫`Array.ConvertAll`。另外,「Distinct」是.Net 3.5的新功能。 – SLaks 2011-01-10 18:17:26