【发布时间】:2012-06-13 17:31:45
【问题描述】:
我想弄清楚一些事情。我有一种方法可以将一些项目添加到名为“cbSize”的ComboBox 中。我意识到如果我在其中添加两种类型的数据,代码会崩溃。这是因为ComboBox 只能容纳一种数据吗?
items.Add(1);
items.Add(10);
items.Add(100);
items.Add(2);
items.Add(20);
items.Add(3);
items.Add(30); //works fine if add numbers only
//items.Add("4"); //will crash if mix both numbers and text
//items.Add("2"); //works fine if add text only
//then sort them out
items.Sort();
//now clear original cbSize items
cbSize.Items.Clear();
//and add them back in sorted order
cbSize.Items.AddRange(items.ToArray());
//gotta clear ArrayList for the next time or else things will add up
items.Clear();
【问题讨论】:
-
什么时候出现异常?