【发布时间】:2017-08-04 14:44:52
【问题描述】:
我有一个类似下面帖子的问题:
但是,在帖子中,解决方案连接了重复的字符串。我想做类似的事情,但是使用整数,我不想连接它们,我想添加它们。
所以我想要这个:
var firstDic = new Dictionary<string, int>
{
{"apple", 1},
{"orange", 2}
};
var secondDic = new Dictionary<string, int>
{
{"apple", 3},
{"banana", 4}
};
以某种方式联合成为:
var thirdDic = new Dictionary<string, int>
{
{"apple", 4}, //values from the two "apple" keys added together.
{"orange", 2},
{"banana", 4}
};
有没有什么快速简便的方法可以做到这一点,而不必做一些麻烦的嵌套循环混乱?
【问题讨论】:
标签: c#