| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 370 人关注过本帖
标题:下面三段代码,如何用循环写出?
取消只看楼主 加入收藏
upperc
Rank: 1
等 级:新手上路
帖 子:17
专家分:7
注 册:2008-4-24
收藏
 问题点数:0 回复次数:1 
下面三段代码,如何用循环写出?
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");
搜索更多相关主题的帖子: sum4 private double 如何 
2013-03-04 11:17
upperc
Rank: 1
等 级:新手上路
帖 子:17
专家分:7
注 册:2008-4-24
收藏
得分:0 
程序代码:
变量用数组,这样就能循环了
private double []sum  = new double[]{0,0,0,0,0,0,0,0,0,0};

for(int i=0;i<10;i++)
{
sum[i] += Convert.ToDouble(e.Row.Cells[i+2].Text);
}

e.Row.Cells[0].Text = "合计:";
for(int i=0;i<10;i++)
{
   e.Row.Cells[i+2].Text = sum[i].ToString();
} 
这是在CSDN C#论坛的回复,有学习的朋友可以参考。
2013-03-06 16:01
快速回复:下面三段代码,如何用循环写出?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023812 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved