Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confirming all Keys in a dictionary have populated Values

I have a Dictionary<string, List<string>>

I want to do a check that all Keys in the dictionary have at least 1 item in its corresponding list

like image 820
Jon Avatar asked Jun 29 '10 16:06

Jon


2 Answers

Try the following

bool allPopulated = map.All(p => p.Value != null && p.Value.Count > 0);
like image 109
JaredPar Avatar answered Oct 06 '22 04:10

JaredPar


You can use the Enumerable.All extension method (part of the LINQ extension methods) for this.

bool allPopulated = yourDictionary.All(p => p.Value != null && p.Value.Count > 0);
like image 39
Adam Robinson Avatar answered Oct 06 '22 03:10

Adam Robinson