Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8292747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:35:13+00:00 2026-06-08T13:35:13+00:00

i am using Visual Studio 2010 C++ Express and i mant to add an

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:35:15+00:00Added an answer on June 8, 2026 at 1:35 pm

    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.

    static int UpdateFunc(String^ key, int value)
    {
        return value + 1;
    }
    
    cd->AddOrUpdate("foo", 1, gcnew Func<String^, int, int>(MyClass::UpdateFunc));
    

    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.

    • AddOrUpdate: Add a value, or modify an existing value if that key already exists. (Passes the current value to a delegate, which returns the modification.)
    • GetOrAdd: Add a value, or retrieve the existing value if that key already exists. (Doesn’t modify the dictionary if the key already exists.)
    • this[] (Indexer, uses square brackets): Add a value, or replace the existing value with a constant value.

    If all you want is a simple ‘add’, it’s probably the square brackets you’re interested in.

    cd["foo"] = 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Visual C# Studio 2010 Express and I have oakward problem. I
im writing an application using Visual Studio 2010 Express Edition. I have a problem
I have an app in c# using Visual Studio 2010 express and realized the
I'm building an ASP.net application using Visual Studio Web Developer 2010 Express and have
Using Visual Studio 2010 Express I have a task list open and on filter
i have 32 bit windows 7 and I am using visual studio 2010 express.
I'm using Visual C# Studio 2010 express and have been trying to batch update
using Visual.Web.Developer.2010.Express; using SQL.Server.Management.Studio.2008.R2; What I'm ultimately trying to do is update a sql
using Visual.Web.Developer.2010.Express; using SQL.Server.Management.Studio.2008.R2; Kinda new at C# here.. I got the first row
I am using IIS Express in Visual Studio 2010 and right now it runs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.