Ale*_*erd 7 c# lambda linq-to-entities dictionary
嗨我有两个下一个类型的词典:
SortedDictionary<string, ClusterPatternCommonMetadata> PatternMetaData { get; set; }
Run Code Online (Sandbox Code Playgroud)
ClusterPatternCommonMetadata对象如下所示:
int ChunkQuantity { get; set; }
SortedDictionary<int, int> ChunkOccurrences { get; set; }
Run Code Online (Sandbox Code Playgroud)
首先,我需要找到两个字典中存在的PatternMetaData键的方法.我发现这样:
List<string> commonKeysString=
vector.PatternMetaData.Keys.Intersect(currentFindingVector.PatternMetaData.Keys)
Run Code Online (Sandbox Code Playgroud)
然后我需要找到已创建密钥的常用值...
是否有快速方式(lambda,linq等)才能进行此类操作
谢谢
Ala*_*ter 11
这称为交集.
你可以使用密钥
var data = dictionary1.Keys.Intersect(dictionary2.Keys)
Run Code Online (Sandbox Code Playgroud)
如果要查找两个字典中包含的相等键和值,则只需
var equalDictionarys = dictionary1.Intersect(dictionary2);
Run Code Online (Sandbox Code Playgroud)
您还可以获取具有公共键的整个词典项目:
var commonDictionaryItems = Dic1.Where(d => Dic2.ContainsKey(d.Key)).ToList();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5539 次 |
| 最近记录: |