【发布时间】:2016-02-03 23:03:02
【问题描述】:
这是我的字典:
// weapon <name, dps>
Dictionary<string, int> weapons = new Dictionary<string, int>();
weapons.Add("Chaotic Staff", 1000);
weapons.Add("Abyssal Whip", 800);
weapons.Add("Death Lotus Darts", 900);
weapons.Add("Drygore Mace", 1200);
这是我尝试将我的字典项添加为字符串。例如,我想添加 Chaotic Staff - 1000 作为框中的值之一。
var result = string.Join(", ", weapons.Select(m => m.Key + " - " + m.Value).ToArray()); //copied it from somewhere.
weaponsComboBox.DataSource = new BindingSource(result, null);
weaponsComboBox.DisplayMember = "Key";
weaponsComboBox.ValueMember = "Value"; //Argument Exception error
应该如何更正?我对 BindingSource 和 LINQ 了解甚少。
【问题讨论】:
标签: c# linq dictionary bindingsource argumentexception