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);
}
精彩评论