【发布时间】:2010-04-05 03:13:09
【问题描述】:
我有一个现有的SortedDictionary<string, int> 的要求。现在我正在创建一个不同的 SortedDictionary 并希望将其添加到第一个中。怎么做?
【问题讨论】:
-
第二个也是 SortedDictionary
还是 SortedDictionary >?
标签: c# .net sorteddictionary
我有一个现有的SortedDictionary<string, int> 的要求。现在我正在创建一个不同的 SortedDictionary 并希望将其添加到第一个中。怎么做?
【问题讨论】:
标签: c# .net sorteddictionary
只需将它传递给构造函数:
var copy = new SortedDictionary<string, int>(original);
【讨论】:
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);
}
【讨论】: