LINQ query expression to get sum of numbers which match specified predicate.

Amatya
Posted by Amatya under C# category on | Points: 40 | Views : 830
LINQ query expression to get sum of numbers which match specified predicate.

var dnfList = new List<int> { 10, 20, 30, 40, 50 };
int dnfSum = (from x in dnfList where x > 20 select x).Sum();


Result:
sum: 120

Thanks
Amatya

Comments or Responses

Login to post response