日期:2014-05-17  浏览次数:20981 次

怎么初始化数组急求高手解答,急急急急急急急急
 private Computer[] engineers; 
        

        private void Form1_Load(object sender, EventArgs e)
        {
            engineers=new Computer[3];
            engineers[0].Xinghao = 1;
            engineers[0].Jiage = 8000;
            engineers[0].Rqi = Convert.ToDateTime("2012-08-12");
            engineers[0].Id = 1000;

            engineers[1].Xinghao = 2;
            engineers[1].Jiage = 8000;
            engineers[1].Rqi = Convert.ToDateTime("2012-08-12");
            engineers[1].Id = 1001;

            engineers[2].Xinghao = 11;
            engineers[2].Jiage = 8000;
            engineers[2].Rqi = Convert.ToDateTime("2012-08-12");
            engineers[2].Id = 1002;


            for (int i = 0; i < engineers.Length; i++)
            {
                ListViewItem item = new ListViewItem();
                item.Text = engineers[i].Xinghao.ToString();
                item.SubItems.Add(engineers[i].Jiage.ToString());
                item.SubItems.Add(Convert.ToDateTime(engineers[i].Rqi).ToString());
                item.SubItems.Add(engineers[i].Id.ToString());
                this.listView1.Items.Add(item);
            }
        }
------解决方案--------------------
请问有什么错误!!!
------解决方案--------------------
engineers=new Computer[3];
for(int i=0;i<engineers.Length;i++)
{
engineers[i] = new Computer();
}
------解决方案--------------------
把数组 private Computer[] engineers; 
  换成 private List<Computer> engineers; 
------解决方案--------------------
让后再赋值。。
------解决方案--------------------
Computer[] engineers; 相当于Computer[] enginerrs = null;