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);
}
Questions connexes
- 1. comportement SortedDictionary
- 2. deepcopy A SortedDictionary
- 3. SortedDictionary (C#) - changer la valeur
- 4. Récupération indexée SortedDictionary <>
- 5. SortedList contre SortedDictionary vs. Sort()
- 6. Amélioration du temps d'accès sur SortedDictionary
- 7. SortedDictionary - Comparer uniquement pour le tri
- 8. C# .NET: Comparaison décroissante d'un SortedDictionary?
- 9. vb.net en utilisant SortedDictionary comme source de données combobox
- 10. Comment utiliser Eval() pour référencer des valeurs dans un SortedDictionary dans un répéteur ASP?
- 11. Obtenir la valeur i-th d'une SortedList ou SortedDictionary
- 12. SortedList <>, SortedDictionary <> et Dictionary <>
- 13. Pourquoi chercher dans SortedDictionary <> est SLOWER than lookup dans le dictionnaire <>?
- 14. Itère un dictionnaire ajouter à un autre
- 15. ajouter un élément APRÈS un autre?
- 16. ajouter un fichier à un autre
- 17. SimpleXML: ajouter un arbre à un autre
- 18. Ajouter un autre propertymapping? (AutoMapper)
- 19. Drupal CCK ajouter un autre rappel callback
- 20. ajouter du texte à un autre cadre
- 21. SQL Server ajouter un autre utilisateur
- 22. Comment ajouter un fichier XML à un autre fichier XML
- 23. jQuery: Ajouter un élément après un autre élément
- 24. Comment ajouter un tableau à un autre tableau en PHP?
- 25. Ajouter un autre tuple à un tuple de tuples
- 26. Besoin d'aide pour ajouter un wchar_t à un autre! C++
- 27. Comment ajouter un contrôle personnalisé sur un autre
- 28. Ajouter des contrôles à WinForms dynamiquement dans un autre thread
- 29. "Enregistrer sous" et "Enregistrer et ajouter un autre" dans Admin
- 30. Comment ajouter 1 html pur dans un autre html
est le deuxième aussi SortedDictionary ou est-ce un SortedDictionary >? –