Reputation: 3974
Is there a possible way to iterate N-numbers in LINQ to get a sum on it?
for instance:
var n = 3;
//The part I wonder about if you can do this entirely with LINQ
var t = 0;
for (var i = 0; i < n; i++){
t += i;
}
Upvotes: 0
Views: 2146
Reputation: 118957
Just use Enumerable.Range
to generate your list of numbers then Sum
them
var n = 3;
var sum = Enumerable.Range(0, n).Sum();
Upvotes: 12