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

下面三段代码,如何用循环写出?
private double sum  = 0;
    private double sum1 = 0;
    private double sum2 = 0;
    private double sum3 = 0;
    private double sum4 = 0;
    private double sum5 = 0;
    private double sum6 = 0;
    private double sum7 = 0;
    private double sum8 = 0;
    private double sum9 = 0; 
----------------------------------------
sum += Convert.ToDouble(e.Row.Cells[2].Text);
            sum1 += Convert.ToDouble(e.Row.Cells[3].Text);
            sum2 += Convert.ToDouble(e.Row.Cells[4].Text);
            sum3 += Convert.ToDouble(e.Row.Cells[5].Text);
            sum4 += Convert.ToDouble(e.Row.Cells[6].Text);
            sum5 += Convert.ToDouble(e.Row.Cells[7].Text);
            sum6 += Convert.ToDouble(e.Row.Cells[8].Text);
            sum7 += Convert.ToDouble(e.Row.Cells[9].Text);
            sum8 += Convert.ToDouble(e.Row.Cells[10].Text);
            sum9 += Convert.ToDouble(e.Row.Cells[11].Text);
---------------------------
e.Row.Cells[0].Text = "合计:";
            e.Row.Cells[2].Text = sum.ToString();
            e.Row.Cells[3].Text = sum1.ToString();
            e.Row.Cells[4].Text = sum2.ToString("f");
            e.Row.Cells[5].Text = sum3.ToString("f");
            e.Row.Cells[6].Text = sum4.ToString("f");
            e.Row.Cells[7].Text = sum5.ToString("f");
            e.Row.Cells[8].Text = sum6.ToString("f");
            e.Row.Cells[9].Text = sum7.ToString("f");
            e.Row.Cells[10].Text = sum8.ToString("f");
            e.Row.Cells[11].Text = sum9.ToString("f"); 

------解决方案--------------------

        const int SUMSIZE=10;
        double[] sums;
        public void Init()
        {
            sums=new doub