System::Collections::Generic::Dictionary класс

Dictionary class

Предварительное объявление класса 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)>>
ПараметрОписание
TKeyТип ключа.
TValueТип значения.

Nested classes

Методы

МетодОписание
Dictionary()Создаёт пустой словарь.
Dictionary(const map_t&)Копирует данные из карты.
Dictionary(int)Перегрузка, соответствующая созданию предварительно выделенного словаря; фактически не выполняет выделение.
Dictionary(const SharedPtr<IDictionary<TKey, TValue>>&)Конструктор копирования.
Dictionary(const SharedPtr<IDictionary<TKey, TValue>>&, const SharedPtr<IEqualityComparer<TKey>>&)Конструктор копирования.
Dictionary(const SharedPtr<IEqualityComparer<TKey>>&)Создаёт пустой словарь.
Dictionary(int, const SharedPtr<IEqualityComparer<TKey>>&)Создаёт пустой словарь.
GetEnumerator() overrideСоздаёт объект перечислителя.

Typedefs

Определение типаОписание
IEnumerablePtrУказатель на интерфейс перечисления.
IEnumeratorPtrУказатель на перечислитель.
KeyCollectionИнформация RTTI.
KVPairТип пары «ключ‑значение».
map_tБазовый тип данных.
PtrТип указателя.
ValueCollectionКоллекция значений для извлечения.

Примечания

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()
{
  // Создать экземпляр класса Dictionary-class.
  auto dictionary = MakeObject<Dictionary<int, String>>();

  // Заполнить словарь.
  dictionary->Add(0, u"Foo");
  dictionary->Add(1, u"Bar");
  dictionary->Add(2, u"Baz");

  // Вывести элементы словаря.
  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
*/

См. также