lundi 13 octobre 2014

Sum elements of the array based on index position, preferable with Linq


Vote count:

0




So I have an array



int number = {3 ,5 ,2}


I know



number.Sum() = 10


and



number.Select(x=> sum+x) => {3, 8, 10}


I am looking for a way given a index to return the sum of the elements from index i to N


Example:



Sum(0) = 10
Sum(1) = 7
Sum(2) = 2


I can easily do it with a loop but I was wondering if there was a one-statement Linq that could be used.



asked 1 min ago

Mike

943






Sum elements of the array based on index position, preferable with Linq

Aucun commentaire:

Enregistrer un commentaire