System::Collections::Concurrent::ConcurrentDictionary klasse

ConcurrentDictionary class

Thread‑veilige woordenboekimplementatie. Objecten van deze klasse mogen alleen worden gealloceerd met de System::MakeObject() functie. Maak nooit een instantie van dit type op de stack of met operator new, omdat dit leidt tot runtime‑fouten en/of assertiefouten. Wikkel deze klasse altijd in de System::SmartPtr pointer en gebruik deze pointer om deze door te geven aan functies als argument.

template<class TKey,class TValue>class ConcurrentDictionary : public System::Collections::Generic::Dictionary<TKey, TValue>
ParameterBeschrijving
TKeySleuteltype.
TValueWaarde‑type.

Methoden

MethodeBeschrijving
Add(const TKey&, const TValue&) overrideVoegt een waarde toe aan het woordenboek.
Clear() overrideVerwijdert alle elementen in de container.
CopyTo(ArrayPtr<System::Collections::Generic::KeyValuePair<TKey, TValue>>, int) overrideKopieert container‑elementen naar bestaande array‑elementen.
get_KeysInternal() const overrideHaalt de wrappercollectie op om toegang te krijgen tot de sleutels van de dictionary.
idx_set(const TKey&, TValue) overrideRTTI-informatie.
Remove(const TKey&) overrideVerwijdert element uit de container.
TryAdd(const TKey&, const TValue&)Probeert een sleutel/waarde-paar toe te voegen aan de dictionary.

Typedefs

TypedefBeschrijving
BaseTypeImplementatietype.
ThisTypeDit type.

Opmerkingen

#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;

  // Maak een instantie van de ConcurrentDictionary-klasse aan.
  auto concurrentDictionary = MakeObject<ConcurrentDictionary<int, int>>();

  // Vul de concurrent dictionary.
  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
*/

Zie ook