C# get sum of dictionary values when values are stored as a collection

Hello Experts!

I have a Dictionary storing data as such: Dictionary<string, IList<T>>();

I am trying to select the total number of values without having to use nested foreach loops.

I found this using LinQ,

myRowCnt = deptToEmp.Skip(1).Sum(x => x.Value);

Open in new window


But because value is a Collection, this will not work. I was trying to modify it myself, but I am not familiar with LinQ.

Any help would be greatly appreciated!
I_sAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
käµfm³d 👽Connect With a Mentor Commented:
Or you might modify your original:

myRowCnt = deptToEmp.Skip(1).Sum(x => x.Value.Sum());

Open in new window

0
 
käµfm³d 👽Commented:
Try:

double total = deptToEmp.Values.Sum(x => x.Sum());

Open in new window

0
 
I_sAuthor Commented:
Hey thanks for the responses, I'll try them both when I get back into the office.
0
All Courses

From novice to tech pro — start learning today.