System::Collections::Concurrent::ConcurrentDictionary kelas
ConcurrentDictionary class
Implementasi kamus yang aman terhadap thread. Objek dari kelas ini hanya boleh dialokasikan menggunakan fungsi System::MakeObject(). Jangan pernah membuat instance tipe ini di stack atau menggunakan operator new, karena akan menyebabkan kesalahan runtime dan/atau kegagalan asersi. Selalu bungkus kelas ini ke dalam pointer System::SmartPtr dan gunakan pointer tersebut untuk meneruskannya ke fungsi sebagai argumen.
template<class TKey,class TValue>class ConcurrentDictionary : public System::Collections::Generic::Dictionary<TKey, TValue>
| Parameter | Deskripsi |
|---|
| TKey | Tipe kunci. |
| TValue | Tipe nilai. |
Metode
| Metode | Deskripsi |
|---|
| Add(const TKey&, const TValue&) override | Menambahkan nilai ke dalam kamus. |
| Clear() override | Menghapus semua elemen dalam wadah. |
| CopyTo(ArrayPtr<System::Collections::Generic::KeyValuePair<TKey, TValue>>, int) override | Menyalin elemen kontainer ke elemen array yang sudah ada. |
| get_KeysInternal() const override | Mendapatkan koleksi pembungkus untuk mengakses kunci kamus. |
| idx_set(const TKey&, TValue) override | Informasi RTTI. |
| Remove(const TKey&) override | Menghapus elemen dari wadah. |
| TryAdd(const TKey&, const TValue&) | Mencoba menambahkan pasangan kunci/nilai ke dalam kamus. |
Typedefs
Catatan
#include <system/collections/concurrent/concurrent_dictionary.h>
#include <system/smart_ptr.h>
using namespace System;
using namespace System::Collections::Generic;
int main()
{
const int itemsCount = 32;
// Buat instance kelas ConcurrentDictionary.
auto concurrentDictionary = MakeObject<ConcurrentDictionary<int, int>>();
// Isi kamus konkuren.
for (auto i = 0; i < itemsCount; ++i)
{
concurrentDictionary->Add(i, i * i);
}
Console::WriteLine(concurrentDictionary->idx_get(3));
return 0;
}
/*
This code example produces the following output:
9
*/
Lihat Juga