-9

I have a list:

List<BtnCountViews> btnCountViewsList;

The BtnCountViews class looks like this:

public class BtnCountViews
{
    public int DayOfYear { get; set; }
    public int BtnCount { get; set; }
    public int Views { get; set; }
}

Can someone tell me how I can get the total of BtnCount in the list? Can I use LINQ to do this?

Alan2
  • 23,493
  • 79
  • 256
  • 450
  • 9
    Seems like you haven't even tried anything....Any googling at least? – Gilad Green Dec 13 '17 at 07:31
  • https://stackoverflow.com/questions/4351876/c-sharp-list-of-objects-how-do-i-get-the-sum-of-a-property – Nagaraj S Dec 13 '17 at 07:37
  • 2
    @Alan2 I've seen the BtnCountViews too many times by now for the last days, but with all due respect, how about spending some little time on the essentials in the first place (like 101 LINQ Samples https://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b) – Dan Dohotaru Dec 13 '17 at 07:50

1 Answers1

1

The task can de done by Linq as follows.

int BtnTotal = btnCountViewsList.Sum( iBtnCount => iBtnCount.BtnCount );
Codor
  • 17,447
  • 9
  • 29
  • 56