Jon Jon - 1 year ago 75
C# Question

Calculating Total Count of Items in List<T> for multiple KeyValuePairs in Dictionary<string,List<string>>

I have a


I have multiple KeyValuePairs so int the first KeyValuePair the List may have 10 items in it, the second KeyValuePair may have 100 etc.

I need to work out the total count for all items in each list so in my example above I would have a result of 110.

Answer Source

That's pretty simple:

int sum = dictionary.Sum(x => x.Value.Count);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download