获取两个字典的公用键和公用值 [英] Get common keys and common values of two dictionaries

查看:88
本文介绍了获取两个字典的公用键和公用值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个下一类的字典:

Hi I have two dictionaries of next type:

SortedDictionary<string, ClusterPatternCommonMetadata> PatternMetaData { get; set; }

ClusterPatternCommonMetadata对象看起来像:

The ClusterPatternCommonMetadata object looks like:

int ChunkQuantity { get; set; }

SortedDictionary<int, int> ChunkOccurrences { get; set; }

首先,我需要找到两个字典中存在的PatternMetaData的键的方法.我发现是这样的:

First I need the way to find keys of PatternMetaData that is exists in two dictionaries. I find this way:

List<string> commonKeysString=
            vector.PatternMetaData.Keys.Intersect(currentFindingVector.PatternMetaData.Keys)

然后我需要找到已建立键的通用值...

Then I need to find common values of the founded keys...

是否有进行这种操作的快速方法(lambda,linq等)

Is there is the fast way (lambda, linq, etc) in order to do such operation

谢谢

推荐答案

这称为交集.

您可以使用

var data = dictionary1.Keys.Intersect(dictionary2.Keys)

如果要查找两个字典中包含的相等键和值,则只需

If you want to find equal keys and values that are contained within both dictionaries then just

var equalDictionarys = dictionary1.Intersect(dictionary2);

这篇关于获取两个字典的公用键和公用值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆