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
- Class Enumerator
方法
| 方法 | 描述 |
|---|---|
| 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 类的实例。
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
*/
另见
- Class BaseDictionary
- Namespace System::Collections::Generic
- Library Aspose.Font for C++