小编Reg*_*gal的帖子

将for(;;)循环转换为foreach

所以我一直在尝试将这些代码转换为每个代码,但我一直遇到问题,而且我不确定如何做到这一点,我唯一能做的就是一个小代码但是它重复了好几次,我仍然是C#的新手并且使用for()所以我真的不知道该怎么做.很抱歉这么新,我感谢所有帮助!

double[] numbers = new double[9.7, 2.2, 4.3, 1.7, 5.6, 3.6, 4.5, 1.3, 4.6, 3.0];

static double ComputeSum(double[] array)
{
    double sum = 0;
    int intCounter;

    for (intCounter = 0; intCounter < array.Length; intCounter++)
    {
        sum += array[intCounter];
    }
    return sum;
}

static double ComputeAverage(double[] array)
{
    return ComputeSum(array) / array.Length;
}
Run Code Online (Sandbox Code Playgroud)

.net c# loops for-loop

1
推荐指数
1
解决办法
171
查看次数

标签 统计

.net ×1

c# ×1

for-loop ×1

loops ×1