Linqify this: Aggregate a subset of a list
Posted
by JMarsch
on Stack Overflow
See other posts from Stack Overflow
or by JMarsch
Published on 2010-05-19T22:31:36Z
Indexed on
2010/05/19
22:40 UTC
Read the original article
Hit count: 362
Suppose I have a list or array of items, and I want to sum a subset of the items in the list. (in my case, it happens to always be a sequential subset).
Here's the old-fashioned way:
int sum = 0;
for(int i = startIndex; i <= stopIndex; i++)
sum += myList[i].TheValue;
return sum;
What's the best way to linqify that code?
© Stack Overflow or respective owner