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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:28:37+00:00 2026-05-15T07:28:37+00:00

I am trying to join two Dictionary collections together based on a common lookup

  • 0

I am trying to join two Dictionary collections together based on a common lookup value.

var idList = new Dictionary<int, int>();
idList.Add(1, 1);
idList.Add(3, 3);
idList.Add(5, 5);

var lookupList = new Dictionary<int, int>();
lookupList.Add(1, 1000);
lookupList.Add(2, 1001);
lookupList.Add(3, 1002);
lookupList.Add(4, 1003);
lookupList.Add(5, 1004);
lookupList.Add(6, 1005);
lookupList.Add(7, 1006);

// Something like this:
var q = from id in idList.Keys
        join entry in lookupList on entry.Key equals id
        select entry.Value;

The Linq statement above is only an example and does not compile. For each entry in the idList, pull the value from the lookupList based on matching Keys.

The result should be a list of Values from lookupList (1000, 1002, 1004).

What’s the easiest way to do this using Linq?

  • 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-15T07:28:38+00:00Added an answer on May 15, 2026 at 7:28 am
    from id in idList.Keys
    where lookupList.ContainsKey(id)
    let value1 = idList[id]
    let value2 = lookupList[id]
    select new {id, value1, value2}
    

    Or, more classically

    from kvp1 in idList
    join kvp2 in lookupList on kvp1.Key equals kvp2.Key
    select new {key = kvp1.Key, value1 = kvp1.Value, value2 = kvp2.Value}
    

    The mistake in your query is one of scoping:

    from a in theAs
    join b in theBs on (leftside) equals (rightside)
    

    a is in scope in the leftside area. b is in scope in the rightside area.

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

Sidebar

Related Questions

I'm trying to join two associative arrays together based on an entry_id key. Both
I'm relatively new SQL queries, and I'm trying to join two tables in order
I have two relatively complex queries that I am trying to join together into
I am trying to join two tables together, but have an odd requirement. Normally
I'm trying to join two relatively simple tables together, but my query is experiencing
I'm trying to join two DataTables together in a similar way to this question:
I am trying to join two tables together using C# linq to entities. One
I'm trying to generate a SQL query that can join two tables together and
I am trying to join two tables; the purpose being able to search and
I am currently using Symfony2 and Doctrine2 and am trying to join two tables

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.