我正在尝试找出一种方法,使用Linq相互比较两个字典,并为DictB
中的键确定DictA
中的最小值。
DictA: { 1,"Ron" },{ 3,"Alice" } DictB: { 1,9 },{ 2,7 },10 },{ 4,8 },{ 5,12 }
假设两个字典上的键都是代表用户及其分数的唯一ID,我希望能够确定在DictA
中用户中得分最低的用户,即用户1
("Ron"
)得分为9。
我假设它必须是类似以下内容的东西:
var pLoser = DictA[
DictB
.Where(x => DictA.ContainsKey(x.Key))
.Aggregate((l,r) => l.Value < r.Value ? l : r)
.Key
];
我想知道这是否是实现我想要的东西的正确方法,或者是否有更好的方法来做到这一点。