【发布时间】:2012-02-03 18:11:07
【问题描述】:
我有 3 个通用词典
static void Main(string[] args)
{
Dictionary<string, string> input = new Dictionary<string, string>();
input.Add("KEY1", "Key1");
Dictionary<string, string> compare = new Dictionary<string, string>();
compare.Add("KEY1", "Key1");
compare.Add("KEY2", "Key2");
compare.Add("KEY3", "Key3");
Dictionary<string, string> results = new Dictionary<string, string>();
我想获取输入列表并将每个值与 compareTo 列表进行比较,如果不存在则将其添加到结果列表中?
【问题讨论】:
-
澄清一下,您希望
compare中的所有成员而不是input中的所有成员?或者input的所有成员不在compare中?我假设前者,但如果后者只是在我的答案中反转操作数。 -
这个问题有点含糊。您想将每个值与
compare列表进行比较,但什么是值?您的意思是input.Values中的string项目之一是否存在于compare.Values中,或者input中的KeyValuePair<string, string>项目之一是否存在于compare中?或者您只是在查看键,正如人们在使用字典的代码中所期望的那样? -
@phoog:我从他在问题中的“比较每个值”中假设他想要任何不同或不存在的值(对于给定键)在结果中。那是正确的杆吗?
标签: c#