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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:21:16+00:00 2026-06-10T09:21:16+00:00

I am trying to join two lists together. Both lists are of the same

  • 0

I am trying to “join” two lists together. Both lists are of the same type and each instance of that type has a unique key. If there are instances with the same key in both lists, then I would like to merge the two instances together with a custom merge function. The final list of items should contain the merged elements plus the instances that were only in one of the two lists in the first place.

This is similar to a Union and a Join, but seems to be subtly different to each of them. A union would give me the right list of keys, but has no facility to merge instances where they share the same key – it would just return one of the instances and ignore the other. A join allows me to merge the repeated instances by supplying a function but it would only return the elements that were in both lists – not one or the other.

Have I missed a good built-in way to do this?

  • 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-10T09:21:18+00:00Added an answer on June 10, 2026 at 9:21 am

    This should be quite easy.

    If I can assume that you have a merge function like this:

    Func<T, T, T> merge = (a, b) => /* your result here */;
    

    Then this should work:

    var intersects = listA.Join(listB, x => x.Id, x => x.Id, (a, b) => merge(a, b));
    var excepts = listA.Except(listB).Concat(listB.Except(listA));
    
    var results = intersects.Concat(excepts);
    

    Let me know if this works.

    • 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 have two relatively complex queries that I am trying to join together into
I am trying to join two Dictionary collections together based on a common lookup
I'm trying to write a LINQ expression that will join two tables and return
I'm trying to associate two entity types in EF4, there is no foreign key
Using extension syntax I'm trying to create a left-join using LINQ on two lists
I am trying to join two tables like this... SELECT * FROM lists l
I'm trying to LEFT JOIN two tables, to get a list of all rows
Hi I am trying to join two bits of information on an MVC view
I have been trying to join two tables (USERS AND USERS_ROLES) based on their

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.