فئة System::Collections::Concurrent::ConcurrentDictionary

ConcurrentDictionary class

تنفيذ قاموس آمن للخيوط. يجب تخصيص كائنات هذه الفئة فقط باستخدام الدالة System::MakeObject() . لا تقم أبدًا بإنشاء نسخة من هذا النوع على المكدس أو باستخدام المشغل new، لأن ذلك سيؤدي إلى أخطاء وقت التشغيل و/أو أخطاء التأكيد. احرص دائمًا على تغليف هذه الفئة في مؤشر System::SmartPtr واستخدام هذا المؤشر لتمريره إلى الدوال كمعامل.

template<class TKey,class TValue>class ConcurrentDictionary : public System::Collections::Generic::Dictionary<TKey, TValue>
Parameterالوصف
TKeyنوع المفتاح.
TValueنوع القيمة.

الطرق

طريقةالوصف
Add(const TKey&, const TValue&) overrideيضيف قيمة إلى القاموس.
Clear() overrideيحذف جميع العناصر في الحاوية.
CopyTo(ArrayPtr<System::Collections::Generic::KeyValuePair<TKey, TValue>>, int) overrideينسخ عناصر الحاوية إلى عناصر مصفوفة موجودة.
get_KeysInternal() const overrideيحصل على مجموعة مغلفة للوصول إلى مفاتيح القاموس.
idx_set(const TKey&, TValue) overrideمعلومات RTTI.
Remove(const TKey&) overrideيزيل العنصر من الحاوية.
TryAdd(const TKey&, const TValue&)يحاول إضافة زوج المفتاح/القيمة إلى القاموس.

Typedefs

تعريف نوعالوصف
BaseTypeنوع التنفيذ.
ThisTypeهذا النوع.

ملاحظات

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

  // إنشاء نسخة من الفئة ConcurrentDictionary-class.
  auto concurrentDictionary = MakeObject<ConcurrentDictionary<int, int>>();

  // ملء القاموس المتزامن.
  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
*/

انظر أيضًا