比较C#中不同大小的两个词典 [英] Compare two dictionaries of different size in C#
本文介绍了比较C#中不同大小的两个词典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个不同大小的不同字典,我们可以比较这两个字典并提取字典1中不存在的值吗?
我是什么尝试过:
我有两个不同大小的不同字典,我们可以比较这两个字典并提取字典1中不存在的值吗? div class =h2_lin>解决方案
使用Linq Except方法:
Dictionary< string,string> d1 = new 字典< string,string>();
d1.Add( Joe, 2,Barfield Way);
d1.Add( Mike, 17,Apollo Avenue);
d1.Add( Jane, 69,Lance Drive);
Dictionary< string,string> d2 = new 字典< string,string>();
d2.Add( Joe, 2,Barfield Way);
d2.Add( Jane, 69,Lance Drive);
var diff = d1.Except(d2);
I have two different dictionaries of different size, can we compare both these and extract the values which are not there in dictionary 1?
What I have tried:
I have two different dictionaries of different size, can we compare both these and extract the values which are not there in dictionary 1?
解决方案
Use the Linq Except method:
Dictionary<string, string> d1 = new Dictionary<string, string>(); d1.Add("Joe", "2, Barfield Way"); d1.Add("Mike", "17, Apollo Avenue"); d1.Add("Jane", "69, Lance Drive"); Dictionary<string, string> d2 = new Dictionary<string, string>(); d2.Add("Joe", "2, Barfield Way"); d2.Add("Jane", "69, Lance Drive"); var diff = d1.Except(d2);
这篇关于比较C#中不同大小的两个词典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文