Accumulation of subsequences of a sequence using C#/Linq

前端 未结 6 1633
醉梦人生
醉梦人生 2021-01-20 01:13

I\'m trying to find a better way of processing a sequence of numbers based on the following requirement: the value of sequence[i] is the sum of its own value pl

6条回答
  •  梦毁少年i
    2021-01-20 01:47

    A non-LINQ version, just to be different:

    List GetSums(List values)
    {
       List sums = new List();
       double total = 0;
       foreach(double d in values)
       {
          total += d;
          sums.Add(total);
       }
       return sums;
    }
    

提交回复
热议问题