首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎么将ListBox中的数据全部存入一个数组中

2012-05-13 
如何将ListBox中的数据全部存入一个数组中如何将ListBox中的数据全部存入一个数组中,不是选定的,而是选框

如何将ListBox中的数据全部存入一个数组中
如何将ListBox中的数据全部存入一个数组中,不是选定的,而是选框中的数据全部写入数组。

[解决办法]

C# code
    string[] ay = ListBox1.Items.OfType<ListItem>().Select(l => l.Text).ToArray();
[解决办法]
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();
[解决办法]
你可以把ListBox.Items理解为数组来使用
C# code
                List<string> temp = new List<string>();                foreach (var item in this.listBox1.Items)                {                    temp.Add(item.ToString());                } 

热点排行