12

I have the following: List<OutputRow> which contains a number of OutputRow objects.

I am wondering if there is a way for me to use a lambda function on the list to return the total sum of the values of a certain propertyX on each OutputRow object in the list.

Example list:

OutputRow.propertyX = 4  
OutputRow.propertyX = 6  
OutputRow.propertyX = 5  

return 15

Baxter
  • 5,363
  • 21
  • 66
  • 104

2 Answers2

27

Test data

var ls=new List<OutputRow>();
ls.Add(new OutputRow(){propertyX=4});
ls.Add(new OutputRow(){propertyX=6});
ls.Add(new OutputRow(){propertyX=5});

Lambda

var total= ls.Sum(x=>x.propertyX);
Arion
  • 30,443
  • 10
  • 68
  • 86
2

SOmething like this:

var yourSum = yourOutputRowList.Sum(x => x.propertyX);
Huske
  • 8,975
  • 2
  • 33
  • 52