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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:09:36+00:00 2026-05-30T19:09:36+00:00

I have two generic Dictionaries. Both have the same keys, but their values can

  • 0

I have two generic Dictionaries. Both have the same keys, but their values can be different. I want to compare the 2nd dictionary with the 1st dictionary. If there are differences between their values, I want to store those values in a separate dictionary.

1st Dictionary
------------
key       Value

Barcode   1234566666
Price     20.00


2nd Dictionary
--------------
key       Value

Barcode   1234566666
Price     40.00


3rd Dictionary
--------------
key       Value

Price     40

Can anyone give me the best algorithm to do this? I wrote an algorithm but it has a lot of loops. I am seeking a short and efficient idea, like a solution using LINQ query expressions or LINQ lambda expressions. I am using .NET Framework 3.5 with C#. I found something about the Except() method, but unfortunately I couldn’t understand what is happening on that method. It would be great if anyone could explain the suggested algorithm.

  • 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-30T19:09:37+00:00Added an answer on May 30, 2026 at 7:09 pm

    If you’ve already checked that the keys are the same, you can just use:

    var dict3 = dict2.Where(entry => dict1[entry.Key] != entry.Value)
                     .ToDictionary(entry => entry.Key, entry => entry.Value);
    

    To explain, this will:

    • Iterate over the key/value pairs in dict2
    • For each entry, look up the value in dict1 and filter out any entries where the two values are the same
    • Form a dictionary from the remaining entries (i.e. the ones where the dict1 value is different) by taking the key and value from each pair just as they appear in dict2.

    Note that this avoids relying on the equality of KeyValuePair<TKey, TValue> – it might be okay to rely on that, but personally I find this clearer. (It will also work when you’re using a custom equality comparer for the dictionary keys – although you’d need to pass that to ToDictionary, too.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two generic lists of type T. Both lists contain same type, and
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two separate views that both show multiple lists of values. Both views
I have two different DataContexts (SQL Databases) that have the same data, just with
Let's say I have two generic lists of the same type. How do I
I have two Generic Lists with the same objects Type T within them. For
I have two generic lists where I want to run a couple of Linq
I have two Generic Lists containing different types, for the sake of example, lets
I have two objects both of the same type, for instance: typedef struct s_Object
I have two MVC3 sites, both hosted on the same server that I've configured

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.