System::Collections::Concurrent::ConcurrentDictionary class

ConcurrentDictionary class

Thread-safe dictionary implementation. Objects of this class should only be allocated using System::MakeObject() function. Never create instance of this type on stack or using operator new, as it will result in runtime errors and/or assertion faults. Always wrap this class into System::SmartPtr pointer and use this pointer to pass it to functions as argument.

template<class TKey,class TValue>class ConcurrentDictionary : public System::Collections::Generic::Dictionary<TKey, TValue>
ParameterDescription
TKeyKey type.
TValueValue type.

Methods

MethodDescription
Add(const TKey&, const TValue&) overrideAdds value into dictionary.
Clear() overrideDeletes all elements in container.
CopyTo(ArrayPtr<System::Collections::Generic::KeyValuePair<TKey, TValue>>, int) overrideCopies container elements to existing array elements.
get_KeysInternal() const overrideGets wrapper collection to access dictionary keys.
idx_set(const TKey&, TValue) overrideRTTI information.
Remove(const TKey&) overrideRemoves element from container.

Typedefs

TypedefDescription
BaseTypeImplementation type.
ThisTypeThis type.

Remarks

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

  // Create the ConcurrentDictionary-class instance.
  auto concurrentDictionary = MakeObject<ConcurrentDictionary<int, int>>();

  // Fill the 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
*/

See Also