我有两个Dictionary<Person,Boolean>
。
字典 a 包含:
Person A -> false
Person B -> true,
Person C -> false;
字典 b 包含:
Person A -> true;
Person D -> false;
我想要一个结果,其中一次包含所有人员,如果一个人员在两个列表之一中都包含 true,则将 bool 值设置为 ture。
我该如何解决这个问题 dict.Union()
?
谢谢小基
最佳答案
听起来你可以使用:
var result = first.Union(second)
.GroupBy(x => x.Key) // Group by dictionary keys
.ToDictionary(g => g.Key, // Key for new dictionary
g => g.Any(p => p.Value)); // Any true values?
关于c# - 联合词典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12781542/