I have a requirement where I already have an existing SortedDictionary<string, int>
. Now I am creating a different SortedDictionary
and like to add this in the first one . How to do it?
views:
82answers:
2
+4
A:
Just pass it to the constructor:
var copy = new SortedDictionary<string, int>(original);
Hans Passant
2010-04-04 18:51:43
A:
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);
}
Ben Voigt
2010-04-04 19:13:09
reason for downvote?
Ben Voigt
2010-04-14 05:06:04