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>
ParameterDeskripsi
TKeyTipe kunci.
TValueTipe nilai.

Metode

MetodeDeskripsi
Add(const TKey&, const TValue&) overrideMenambahkan nilai ke dalam kamus.
Clear() overrideMenghapus semua elemen dalam wadah.
CopyTo(ArrayPtr<System::Collections::Generic::KeyValuePair<TKey, TValue>>, int) overrideMenyalin elemen kontainer ke elemen array yang sudah ada.
get_KeysInternal() const overrideMendapatkan koleksi pembungkus untuk mengakses kunci kamus.
idx_set(const TKey&, TValue) overrideInformasi RTTI.
Remove(const TKey&) overrideMenghapus elemen dari wadah.
TryAdd(const TKey&, const TValue&)Mencoba menambahkan pasangan kunci/nilai ke dalam kamus.

Typedefs

TypedefDeskripsi
BaseTypeTipe implementasi.
ThisTypeTipe ini.

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