开发者

SortedDictionary add one SortedDictionary into another

I have a requirement where I already have an existing SortedDictionary<string, int>. Now I am creating a different SortedD开发者_开发问答ictionary and like to add this in the first one . How to do it?


Just pass it to the constructor:

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<string, int> first, second;
first = FillFirst();
second = FillSecond();

foreach (KeyValuePair<string, int> kvp in second) {
  first.Add(kvp.Key, kvp.Value);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜