J'ai une exigence où j'ai déjà un SortedDictionary<string, int>
existant. Maintenant je crée un SortedDictionary
différent et aime ajouter ceci dans le premier. Comment faire?SortedDictionary ajouter un SortedDictionary dans un autre
1
A
Répondre
4
Il suffit de passer au constructeur:
var copy = new SortedDictionary<string, int>(original);
1
SortedDictionary<TKey,TValue>
ne fournit pas une fonction AddRange(IEnumerable<KeyValuePair<TKey, TValue>>)
, de sorte que vous aurez à faire à la dure, un élément à la fois.
SortedDictionary<string, int> first, second;
first = FillFirst();
second = FillSecond();
foreach (KeyValuePair<string, int> kvp in second) {
first.Add(kvp.Key, kvp.Value);
}
est le deuxième aussi SortedDictionary ou est-ce un SortedDictionary >? –