[英]SortedDictionary add one SortedDictionary into another
I have a requirement where I already have an existing SortedDictionary<string, int>
. 我已经有一个现有
SortedDictionary<string, int>
。 Now I am creating a different SortedDictionary
and like to add this in the first one . 现在,我正在创建一个不同的
SortedDictionary
并喜欢在第一个中添加它。 How to do it? 怎么做?
只需将其传递给构造函数即可:
var copy = new SortedDictionary<string, int>(original);
SortedDictionary<TKey,TValue>
doesn't provide an AddRange(IEnumerable<KeyValuePair<TKey, TValue>>)
function, so you'll have to do it the hard way, one item at a time. SortedDictionary<TKey,TValue>
不提供AddRange(IEnumerable<KeyValuePair<TKey, TValue>>)
函数,因此您将不得不用困难的方式一次完成一项。
SortedDictionary<string, int> first, second;
first = FillFirst();
second = FillSecond();
foreach (KeyValuePair<string, int> kvp in second) {
first.Add(kvp.Key, kvp.Value);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.