繁体   English   中英

如何在C#Windows应用程序中用国家名称填充组合框

[英]How to fill combobox with country names in a C# windows application

我尝试下面的代码用国家名称填充组合框

private void PopulateCountryComboBox()
{
            RegionInfo country = new RegionInfo(new CultureInfo("en-US", false).LCID);
            List countryNames = new List();
            foreach (CultureInfo cul in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
            {
                country = new RegionInfo(new CultureInfo(cul.Name, false).LCID);
                countryNames.Add(country.DisplayName.ToString());
            }

            IEnumerable nameAdded = countryNames.OrderBy(names => names).Distinct();

            foreach (string item in nameAdded)
            {
                cmbcountry.Items.Add(item);

            }
}

我收到以下错误

使用通用类型'System.Collections.Generic.List'需要1个类型参数

List<T>是通用集合。 您需要提供将要列出的类型。

尝试:

List<string> countryNames = new List<string>();

修改

  RegionInfo country = new RegionInfo(new CultureInfo("en-US", false).LCID);
  List countryNames = new List();

RegionInfo country = new RegionInfo(new CultureInfo("en-US", false).LCID);
  List<string> countryNames = new List<string>();

这可能会解决您的问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM