C#  我要把把listbox里面的值放到一个数组里面
for (int i = 0; i <= listBox1.Items.Count - 1; i++)
{
  String[] xmess ={listbox1.items[i].Tostring()}
}
这样的代码只能吧listbox里面最后的一个值放到数组里面,请问各位大侠有什么错误?谢谢了!!

解决方案 »

  1.   

    String[] xmess;
    for (int i = 0; i <= listBox1.Items.Count - 1; i++)
    {
      xmess[i] =listbox1.items[i].Tostring();
    }
      

  2.   

    List<String> lst=new List<string>();
    for (int i = 0; i <= listBox1.Items.Count - 1; i++)
    {
      List.Add(listbox1.items[i].Tostring());
    }string[] arr= new string[listBox1.Items.Count]; 
    arr[i]=listbox1.items[i].Tostring();
      

  3.   

    这么改了它提示说:使用了未赋值的局部变量“xmess“,怎么回事啊,ccitzs,谢谢了
      

  4.   

     String[] xmess = new string[listBox1.Items.Count];
                for (int i = 0; i <= listBox1.Items.Count - 1; i++)
                {
                    xmess[i] = listBox1.Items[i].ToString();
                }
      

  5.   

    sorry 忘记申明大小了
    String[] xmess=new String[listBox1.Items.Count];这样申明
      

  6.   

    搞定了啊,谢谢大家了啊wuyq11,还有ccitzs