فئة 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
ملاحظات
#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
*/
انظر أيضًا