gpt4 book ai didi

c# - 从 2 个匹配的字典中创建一个新字典

转载 作者:太空宇宙 更新时间:2023-11-03 21:33:45 25 4
gpt4 key购买 nike

 labelMap = new Dictionary<string, int>();
branchLineMap = new Dictionary<string, int>();

如果第一个字典的一个键与另一个字典的另一个键匹配,那么我需要制作一个新字典,其中 branchlineMap 的值成为键,LabelMap 的值成为值。如何在遍历整个字典时执行此操作?

最佳答案

使用 WhereToDictionary方法,你可以这样做:

var newDictionary = labelMap
.Where(x => branchLineMap.ContainsKey(x.Key))
.ToDictionary(x => branchLineMap[x.Key], x => x.Value);

关于c# - 从 2 个匹配的字典中创建一个新字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22925611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com