Summing the previous values in an IEnumerable

前端 未结 7 2303
有刺的猬
有刺的猬 2021-01-04 02:36

I have a sequence of numbers:

var seq = new List { 1, 3, 12, 19, 33 };

and I want to transform that into a new sequence where

7条回答
  •  说谎
    说谎 (楼主)
    2021-01-04 02:47

    var seq = new List { 1, 3, 12, 19, 33 }; 
    
    for (int i = 1; i < seq.Count; i++)
    {
       seq[i] += seq[i-1];
    }
    

提交回复
热议问题