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

  • SEARCH
  • Home
  • 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 8848843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:29:56+00:00 2026-06-14T12:29:56+00:00

So I have a concurrent dictionary defined as such ConcurrentDictionary<string, ConcurrentDictionary<string, ConcurrentDictionary<string, SomeObject>>>(); I

  • 0

So I have a concurrent dictionary defined as such

 ConcurrentDictionary<string, ConcurrentDictionary<string, ConcurrentDictionary<string, SomeObject>>>();

I know that seems a little convoluted but the structure is valid…

Now my problem is that I have say x number of instances of these dictionaries for x different sources and for statistical purposes they need to be merged/amalgamated/aggregated into one single dictionary of the same structure…

Anyone any ideas on the best approach? I know I could create a new dictionary of the same structure; loop through each of the dictionaries to be amalgamated and at each level checking the new dictionary for those keys etc and adding or updating based on the result of that determination…

But that seems slightly unwieldy to me… any LINQ geniuses out there that could lend a hand?

[Note – I just made one important edit – the output dictionary is of the exact same structure as the input dictionaries]

  • 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-14T12:29:57+00:00Added an answer on June 14, 2026 at 12:29 pm

    LINQ doesn’t help here, as you don’t want to query a collection but manipulate one.

    As said in the comments above, using a ConcurrentDictionary<Tuple<string, string, string>, SomeObject> would simplify things a bit. You could do the following then:

    using MyDict = ConcurrentDictionary<Tuple<string, string, string>, SomeObject>;
    
    MyDict Merge(IEnumerable<MyDict> dicts)
    {
        MyDict result = new MyDict();
    
        foreach (var dict in dicts)
        {
            foreach (var kvp in dict)
            {
                result.AddOrUpdate(
                    kvp.Key,        // If the key does not exist, add the value;
                    kvp.Value,      // otherwise, combine the two values.
                    (key, value) => Combine(value, kvp.Value)
                );
            }
        }
    
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have Dictionary<string, SomeClass> which will be accessed heavily by multiple concurrent threads
I have four level data structure defined like this: Dictionary<Type1, Dictionary<Type2, Dictionary<Type3, List<Type4>>>> The
I have a ConcurrentDictionary object that I would like to set to a Dictionary
I have a multithreaded application that has many concurrent operations going on at once.
We have a load test that runs of 100 concurrent users. We also have
Possible Duplicate: Is stl vector concurrent read thread-safe? I have a multi-threaded program that
.NET 4 includes new concurrent data structures. The Bag and Dictionary collections have obvious
If I have this ConcurrentDictionary: public class User { public string Context { get;
We have a multi-tenant application with running site instances stored in a ConcurrentDictionary<string, SiteInstance>
I have public static readonly Dictionary<string, EventHandler> CacheHandlers = new Dictionary<string, EventHandler>(); and I

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.