فئة 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>
معاملالوصف
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.
  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
*/

انظر أيضًا