System::Collections::Concurrent::ConcurrentDictionary klass

ConcurrentDictionary class

Trådsäker ordboksimplementation. Objekt av denna klass bör endast allokeras med System::MakeObject()-funktionen. Skapa aldrig en instans av denna typ på stacken eller med operatorn new, eftersom det kan leda till körfel och/eller påståendefel. Omslut alltid denna klass med System::SmartPtr-pekare och använd denna pekare för att skicka den till funktioner som argument.

template<class TKey,class TValue>class ConcurrentDictionary : public System::Collections::Generic::Dictionary<TKey, TValue>
ParameterBeskrivning
TKeyNyckeltyp.
TValueVärdetyp.

Metoder

MetodBeskrivning
Add(const TKey&, const TValue&) overrideLägger till värde i ordboken.
Clear() overrideTar bort alla element i behållaren.
CopyTo(ArrayPtr<System::Collections::Generic::KeyValuePair<TKey, TValue>>, int) overrideKopierar behållarelement till befintliga arrayelement.
get_KeysInternal() const overrideHämtar omslagskollektion för att komma åt ordbokens nycklar.
idx_set(const TKey&, TValue) overrideRTTI-information.
Remove(const TKey&) overrideTar bort element från behållaren.
TryAdd(const TKey&, const TValue&)Försöker lägga till nyckel/värde-par i ordboken.

Typedefs

TypedefBeskrivning
BaseTypeImplementationstyp.
ThisTypeDenna typ.

Anmärkningar

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

  // Skapa en instans av ConcurrentDictionary-klassen.
  auto concurrentDictionary = MakeObject<ConcurrentDictionary<int, int>>();

  // Fyll den samtidiga ordboken.
  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
*/

Se även