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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:26:15+00:00 2026-06-13T06:26:15+00:00

I am looking for efficient way to combine multiple hashsets (based on object key)

  • 0

I am looking for efficient way to combine multiple hashsets (based on object key) while preserving non key values (such as Version below).

class MyObject {
    public string Key {get; set;}
    public long Version {get; set;}
    override GetHashCode() { *key* }
    override Equals(...) { *key* }
}

in the and, i need to combine hash sets into a master list, but also all Versions.

I can make the union of 3 sets in this way:

for (var o in List1.Union(List2).Union(List3))
    Console.WriteLine("{0} : {1}", o.Key, o.Version)

this only shows the versions from one of the lists (List1, or whatever list contains the item).

I need to compile these into a result with all versions..

Something i wish i could do like this:

for (var o in List1.Union(List2).Union(List3).Select((a,b,c) => new DiffObj(){Key=a.Key,VersionA=a.Version,VersionB=b.Version,VersionC=c.Version}))
    Console.WriteLine("{0} : {1},{2},{3}", o.Key, o.VrsionA, o.VersionB, VersionC);

is that possible with hashsets?

update

it is important to keep track which list had which version (in the final result).

  • 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-13T06:26:16+00:00Added an answer on June 13, 2026 at 6:26 am

    It sounds like you want a grouping:

    var grouped = list1.Select(x => new { List=1, Item=x })
                       .Concat(list2.Select(x => new { List=2, Item=x }))
                       .Concat(list3.Select(x => new { List=3, Item=x }))
                       .GroupBy(pair => pair.Item);
    

    Then you can just iterate over each group, which will contain equal values according to Equals and GetHashCode, but which can still be distinct. The List value will indicate which list each item came from.

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

Sidebar

Related Questions

I am looking for an efficient way to detect the number of unique values
I'm looking for an efficient way to chance a string such that all sequences
While looking into Efficient way to compute p^q (exponentiation), where q is an integer
I'm looking for an efficient way to compare and get differences between two XML-based
I'm looking for an efficient way to keep multiple databases (on different servers) sync
I'm looking for the efficient way of replacing approximate values (ushort[100]) for their target
I'm looking for an efficient way to get the list of unique commit authors
I have a table which contains many records. I'm looking for an efficient way
Looking for suggestions for an efficient way to maintain basic audit fields for entities
I am looking for a more efficient way to do comparisons between all elements

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.