Classe System::Collections::Generic::Dictionary

Dictionary class

Déclaration anticipée de la classe Dictionary.

template<typename TKey,typename TValue>class Dictionary : public System::Collections::Generic::BaseDictionary<std::unordered_map<TKey, TValue, EqualityComparerHashAdapter<TKey>, EqualityComparerAdapter<TKey>, ASPOSE_MAP_ALLOCATOR_TYPE(TKey, TValue)>>
ParamètreDescription
TKeyType de clé.
TValueType valeur.

Nested classes

Méthodes

MéthodeDescription
Dictionary()Crée un dictionnaire vide.
Dictionary(const map_t&)Copie les données depuis la map.
Dictionary(int)Surcharge correspondant à la création d’un dictionnaire pré‑alloué ; ne fait en fait aucune allocation.
Dictionary(const SharedPtr<IDictionary<TKey, TValue>>&)Constructeur de copie.
Dictionary(const SharedPtr<IDictionary<TKey, TValue>>&, const SharedPtr<IEqualityComparer<TKey>>&)Constructeur de copie.
Dictionary(const SharedPtr<IEqualityComparer<TKey>>&)Crée un dictionnaire vide.
Dictionary(int, const SharedPtr<IEqualityComparer<TKey>>&)Crée un dictionnaire vide.
GetEnumerator() overrideCrée un objet énumérateur.

Typedefs

TypedefDescription
IEnumerablePtrPointeur vers l’interface énumérable.
IEnumeratorPtrPointeur vers l’énumérateur.
KeyCollectionInformations RTTI.
KVPairType de paire clé-valeur.
map_tType de données sous-jacent.
PtrType de pointeur.
ValueCollectionCollection de valeurs à extraire.

Remarques

Dictionary that maps values to keys. Objects of this class should only be allocated using System::MakeObject() function. Never create instance of this type on stack or using operator new, as it will result in runtime errors and/or assertion faults. Always wrap this class into System::SmartPtr pointer and use this pointer to pass it to functions as argument.

#include <system/collections/dictionary.h>
#include <system/smart_ptr.h>

using namespace System;
using namespace System::Collections::Generic;

int main()
{
  // Créer l'instance de la classe Dictionary.
  auto dictionary = MakeObject<Dictionary<int, String>>();

  // Remplir le dictionnaire.
  dictionary->Add(0, u"Foo");
  dictionary->Add(1, u"Bar");
  dictionary->Add(2, u"Baz");

  // Imprimer les éléments du dictionnaire.
  for (const auto &pair: dictionary)
  {
    std::cout << pair.get_Key() << " - " << pair.get_Value() << std::endl;
  }

  return 0;
}
/*
This code example produces the following output:
0 - Foo
1 - Bar
2 - Baz
*/

Voir aussi