C# 检查字典中的列表值是否为空

C# 检查字典中的列表值是否为空,c#,list,dictionary,C#,List,Dictionary,我使用以下词典: 字典 如何简单地检查string类型的值->List之一是否为空 然后还有一个问题,您如何看待list==null案例 如果要将其视为空列表,则: dictionary.Values.Any(list => list?.Any() ?? false) 如果没有: dictionary.Values.Any(list => list?.Any() ?? true) 尝试使用Linq: 字典=。。。 bool hasNotEmptyValues=字典 .Any(p

我使用以下词典:

字典
如何简单地检查string类型的值->
List
之一是否为空

然后还有一个问题,您如何看待
list==null
案例

如果要将其视为空列表,则:

dictionary.Values.Any(list => list?.Any() ?? false)
如果没有:

dictionary.Values.Any(list => list?.Any() ?? true)
尝试使用Linq:

字典=。。。
bool hasNotEmptyValues=字典
.Any(pair=>pair.Value!=null&&pair.Value.Any());

您可以按如下方式使用Linq

var HasNonemptyList = dictionary.Values.Any(iList => iList.Count() > 0)

dictionary[yourDateTime].Any()
?您想知道某个特定的字典是否不为空、是否没有一个为空或全部为空吗?与我的答案几乎相同,尽管
Any()
Count()>0更明确。如果是为了挤出最后一点性能,可以使用本机的
List.Count
属性。
dictionary.Values.Any(list => list?.Any() ?? true)
 Dictionary<DateTime,List<string>> dictionary = ...

 bool hasNotEmptyValues = dictionary
   .Any(pair => pair.Value != null && pair.Value.Any());
var HasNonemptyList = dictionary.Values.Any(iList => iList.Count() > 0)