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>
| Parameter | Beskrivning |
|---|
| TKey | Nyckeltyp. |
| TValue | Värdetyp. |
Metoder
| Metod | Beskrivning |
|---|
| Add(const TKey&, const TValue&) override | Lägger till värde i ordboken. |
| Clear() override | Tar bort alla element i behållaren. |
| CopyTo(ArrayPtr<System::Collections::Generic::KeyValuePair<TKey, TValue>>, int) override | Kopierar behållarelement till befintliga arrayelement. |
| get_KeysInternal() const override | Hämtar omslagskollektion för att komma åt ordbokens nycklar. |
| idx_set(const TKey&, TValue) override | RTTI-information. |
| Remove(const TKey&) override | Tar bort element från behållaren. |
| TryAdd(const TKey&, const TValue&) | Försöker lägga till nyckel/värde-par i ordboken. |
Typedefs
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