Summation using Lambda C# 3.0
- by Newbie
I have a small thing.
public int GetSum(List<int> x)
{
foreach (int i in x) sum += i;
return sum;
}
where x is a List of integers defined as
List<int> l = new List<int>();
l.Add(4); l.Add(2); l.Add(5); l.Add(8); l.Add(6);
and has been passed as GetSum(l)
Is it possible to rewrite the above foreach loop using a lambda?
Reason: I started looking into the lambda stuffs since yesterday and is interested to learn .. however simple it may be.
Thanks.