本文介绍了如何比较两个词典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一本词典使用

I have a dictionary Used

Dim Used As New Dictionary(Of Integer, Boolean)
111,true
5,true
125,true



我有第二本字典ByteDic


I have second dictionary ByteDic

Dim ByteDic As Dictionary(Of byte, Integer)
111,1233
22,334
125,123
10, 128



我想选择ByteDic的最大值,该密钥不包含二手(我想从ByteDic中选择334值)



我尝试过:




I want select max value of ByteDic that key not contain by Used (I want select 334 value from ByteDic)

What I have tried:

int MaxValue = ByteDic.Select(x => Used.Keys.ToList.IndexOf(x.Key) > -1).Max;

Dim MaxValue As Integer = ByteDic.Select(Function(x) Used.Keys.ToList.IndexOf(x.Key) > -1).Max

推荐答案

Dim result = ByteDic.Where(Function(x) Not used.Any(Function(y) y.Key.Equals(x.Key))).Max(Function(x) x.Value)






or

Dim result = ByteDic.Where(Function(x) Not used.Keys.Contains(x.Key)).Max(Function(x) x.Value)






or

Dim result = ByteDic.Where(Function(x) Not used.ContainsKey(x.Key)).Max(Function(x) x.Value)


这篇关于如何比较两个词典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-23 17:07