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 6575631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:24:38+00:00 2026-05-25T15:24:38+00:00

I have 2 dictionnary with similaire struture Dictionary<string, List<int>> Origins and Dictionary<string, List<int>> Changes

  • 0

I have 2 dictionnary with similaire struture

Dictionary<string, List<int>> Origins

and

Dictionary<string, List<int>> Changes

I have create Origins in the beginning. It is a copy of the begining state.
Example :

Origins["toto"] = new List<int>(){1,2,3};
Origins["tata"] = new List<int>();
Origins["titi"] = new List<int>(){1,2};

After an user action, I keep the changes in the Changes dictionnary.
Basicly the user can add or remove some number linked to the string. So i keep all the trace of any change like this:

example: if the user add a 1 in “tata”
in the dictionary Changes a have
“tata” have 1

if the user add a 4 in “toto”
in the dictionary Changes a have
“toto” have 1,2,3,4

if the user remove 1 in “titi”
in the dictionary Changes a have
“titi” have 2

I need the Changes dictionnary for know when the user return to original state, with a simple comparaison.

If no change is done for a string, the Changes dictionnary do not have any entry for this string.

After many changes, the user can Save the changes.
So now i need to find all the add and remove operations.

My first idea is to compare the two dictionnary , to see the operation add and the operation remove. But how ?
If I compare the lists for the same string, i may know the difference,but i’m stuck here.
And maybe there are a better way to do this ? Any suggestion ?

  • 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-05-25T15:24:39+00:00Added an answer on May 25, 2026 at 3:24 pm

    You have the following cases:

    1. A new string key is added to Changes, along with some associated values.
    2. The values for an existing string key are changed (values added or removed).

    In case (1) you’ll have an entry in Changes that does not exist in Origins. In case (2) you’ll have an entry in both but with a different list of values.

    (The values I’m going to assume are a mathematical set, i.e. that a particular value can appear in there only once and that the ordering insignificant. If that’s not the case then you will have to modify the approach somewhat.)

    To detect case (1), you can find the keys that are unique:

    IEnumerable<string> newKeys = Changes.Keys.Except(Origins.Keys);
    

    Obviously every value in Changes for a new key will need to be ‘added’. You can simply iterate the newKeys enumerable and retrieve the values from Changes:

    foreach (string key in newKeys)
    {
        IEnumerable<int> addedValues = Changes[key];
        // your processing here
    }
    

    To detect case (2), you will need to iterate the dictionary and compare the set of values in Changes with Origins. To do that we’ll iterate Origins to get the key and original values and then retrieve the item using the key from Changes. (We will do it this way around as, if we iterated Changes instead we would potentially end up with new, added keys that do not exist in Origins and that is another case we would have to deal with.)

    foreach (KeyValuePair<string, List<int>> entry in Origins)
    {
        List<int> originsValues = entry.Value;
        List<int> changesValues;
    
        // handle no key in Changes (as pointed out by Guillaume V). 
        if (!Changes.TryGet(entry.Key, out changesValues)) changesValues = originsValues;
    
        IEnumerable<int> removedValues = originsValues.Except(changesValues);
        IEnumerable<int> addedValues = changesValues.Except(originsValues);
    
        // your processing here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Dictionary<string,int> that has the potential to contain upwards of 10+ million
Say I have a data structure like a Dictionary<string, Dictionary<string, int>> or similar, and
I have a Dictionary<string, someobject> . EDIT: It was pointed out to me, that
I have the following code: public static class ScraperMasterUriDetails { public static Dictionary<Guid, string>
Suppose I have a Dictionary<String,String> , and I want to produce a string representation
I have an ordered list (a dictionary - 100K words) and many words to
I have a Dictionary<string, XMLMessage> where XMLMessage is a struct: private struct XMLMessage {
I have a dictionary, Dictionary listOfProducts. This listOfProducts can have hundreds of products. string
I have a dictionary of type Dictionary<Guid,int> I want to return the first instance
I have a dictionary, where the key is a string and the value is

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.