我试图去具体的项目在ListBox(asp.net,C#) 并检查它是否是空或不是:ListBox中获取特定项目的值
if (ListBox.Items[0] == null)
{
if (HowMany.Text == arrOfWords[0])
{
ListBox.Items.Add(arrOfWords[0]);
ErrorMessege.Text = "Good!";
}
}
它返回的是:指数超出范围。必须是非负数且小于集合的大小。 参数名称:索引
这是为什么? 谢谢!
在调试模式下,它甚至没有输入第一个if语句。即使我试图让if((ListBox.Items.Count> 0)&&(ListBox.Items [0] == null)) – thormayer 2012-01-07 01:52:20
在第一个if条件中放置断点并查看列表框中存在多少项和arrOfWords – Shyju 2012-01-07 01:54:00
默认情况下,列表框在应用程序第一次运行时呈现0个项目,而“arrOfWords”每次至少呈现一个。 – thormayer 2012-01-07 01:57:16