Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if list values in dictionary are not empty

I use the following dictionary:

Dictionary<DateTime, List<string>> dictionary

How can I simply check whether one of values -> List of type string is not empty?

like image 924
maciejka Avatar asked Sep 01 '25 17:09

maciejka


2 Answers

Try using Linq:

 Dictionary<DateTime,List<string>> dictionary = ...

 bool hasNotEmptyValues = dictionary
   .Any(pair => pair.Value != null && pair.Value.Any());
like image 157
Dmitry Bychenko Avatar answered Sep 04 '25 09:09

Dmitry Bychenko


You could use Linq as follows.

var HasNonemptyList = dictionary.Values.Any(iList => iList.Count() > 0)
like image 41
Codor Avatar answered Sep 04 '25 09:09

Codor