转自:http://www.myexception.cn/c-sharp/373798.html
如何将ListBox中的数据全部存入一个数组中
如何将ListBox中的数据全部存入一个数组中,不是选定的,而是选框中的数据全部写入数组。
------解决方案1--------------------------------------------------------
C# code
string[] ay = ListBox1.Items.OfType<ListItem>().Select(l => l.Text).ToArray();
------解决方案2--------------------------------------------------------
C# code
ListBox listbox1 = new ListBox();
listbox1.Items.Add("ab");
listbox1.Items.Add("abc");
listbox1.Items.Add("abcd");
string[] ss = listbox1.Items.Cast<string>().ToArray();
------解决方案3--------------------------------------------------------
你可以把ListBox.Items理解为数组来使用
C# code
List<string> temp = new List<string>();
foreach (var item in this.listBox1.Items)
{
temp.Add(item.ToString());
}