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指向枚举器的指针。
KeyCollectionRTTI 信息。
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 类的实例。
  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
*/

另见