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

解决方案 »

  1.   

    string[] ay = ListBox1.Items.OfType<ListItem>().Select(l => l.Text).ToArray();
      

  2.   


                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理解为数组来使用                List<string> temp = new List<string>();
                    foreach (var item in this.listBox1.Items)
                    {
                        temp.Add(item.ToString());
                    }