C# 获取ListBox里面的数据

如图 ListBox 有4条数据,我想把它里面的数据存进后台的数组里做循环添加,应该怎么写啊?
string []x=??
说明下是C#桌面程序

第1个回答  2012-09-12
//new 一个长度为 listBox1.Items.Count的数组
int[] a = new int[listBox1.Items.Count];
//循环便利listBox1中的每一项

for (int i = 0; i < listBox1.Items.Count; i++)
{
//赋值给数组

a[i] = Convert.ToInt32(listBox1.Items[i]);
//MessageBox.Show(a[i].ToString());
}本回答被提问者和网友采纳
第2个回答  2012-09-12
不要用数组,用List<string>
List<string> listStr = new List<string>();
foreach (var v in listBox1.Items)
{
listStr.Add(v.ToString());
}
这样有个好处,无论listBox里有几条数据都可以取出
listStr可以像普通数组一样使用
listStr[0]=***;
第3个回答  2012-09-12
listBox1.DataSource

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网