数组超出了索引值的范围

long[] sid=new long[dataGridView2.Rows.Count-1];
double[] sweight=new double[dataGridView2.Rows.Count-1];
            for (int i = 0; i < dataGridView2.Rows.Count; i++)
   {
       sid[i]=Convert.ToInt64(dataGridView2.Rows[i].Cells[1].Value.ToString());
       sweight[i]=Convert.ToDouble(dataGridView2.Rows[i].Cells[3].Value.ToString());
       MessageBox.Show(sid[i].ToString()+"  "+sweight[i].ToString());
   }


以上代码是错误的sid,sweight两个数组长度不对,应该是

long[] sid=new long[dataGridView2.Rows.Count];
double[] sweight=new double[dataGridView2.Rows.Count];


 

你可能感兴趣的:(c#,我的挑战杯历程)