i am using Visual Studio 2010 C++ Express and i mant to add an item to my ConcurrentDictionary:
i have such code:
String^ key = gcnew String("key");
int value = 123;
myDictionary->AddOrUpdate(key,value,/*WHAT TO ADD HERE?*/);
AddOrUpdate Method takes 3 argument, not like normal Dictionary 2.
Microsoft sites says it takes such arguments:
public:
TValue AddOrUpdate(
TKey key,
TValue addValue,
Func<TKey, TValue, TValue>^ updateValueFactory
)
on microsoft sites i also found code in C#:
cd.AddOrUpdate(1, 1, (key, oldValue) => oldValue + 1);
but it does not work in C++. what i must put as 3rd argument?
The third parameter is a delegate, which in the C# sample code you found is a lambda. However C++/CLI does not support lambdas, so you’d have to do it with a standalone method.
However, you said “I want to add an item to my ConcurrentDictionary”. There’s no simple “add” method, because it’s always the case that other thread may have modified the ConcurrentDictionary. Therefore, there are a couple choices for how to put stuff in the dictionary.
If all you want is a simple ‘add’, it’s probably the square brackets you’re interested in.