-4

I have this Class:

public class C1
{
    publice double[] p1 { get; set; }
}

And here I have instanced it in List<>

List<C1> clist = new List<C1>();

I would like to sum the item in the property p1?

demo
  • 6,038
  • 19
  • 75
  • 149
  • 2
    Does this answer your question? [C# List of objects, how do I get the sum of a property](https://stackoverflow.com/questions/4351876/c-sharp-list-of-objects-how-do-i-get-the-sum-of-a-property) – demo Nov 07 '19 at 09:16
  • Do you want the sum per object `C1`, or the overall sum of all objects of type `C1`? – MakePeaceGreatAgain Nov 07 '19 at 09:24

1 Answers1

0

Just do:

clist.Sum(i => i.p1.Sum());
Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69
  • Hey you might not want to answer very obvious duplicates with practically a code only answer. Not my downvote but I think that's why. – EpicKip Nov 07 '19 at 09:39
  • @EpicKip To be fair, we still have no real dupe - although I bet there is one. Anyway I agree not to answer such questions. – MakePeaceGreatAgain Nov 07 '19 at 10:46
  • @EpicKip From my perspective the dupe does not match, because of my question in the comments above - otherwise I´d had used my hammer already :) – MakePeaceGreatAgain Nov 07 '19 at 11:28
  • @HimBromBeere To be honest I hadn't noticed it was an array. He can apply the dupe target answer 1 level deeper for succes though. – EpicKip Nov 07 '19 at 12:01