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

  • Home
  • SEARCH
  • 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 8288679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:19:32+00:00 2026-06-08T12:19:32+00:00

I have two classes which share two common attributes, Id and Information. public class

  • 0

I have two classes which share two common attributes, Id and Information.

public class Foo
{
     public Guid Id { get; set; }

     public string Information { get; set; }

     ...
}
public class Bar
{
     public Guid Id { get; set; }

     public string Information { get; set; }

     ...
}

Using LINQ, how can I take a populated list of Foo objects and a populated list of Bar objects:

var list1 = new List<Foo>();
var list2 = new List<Bar>();

and merge the Id and Information of each into a single dictionary:

var finalList = new Dictionary<Guid, string>();

Thank you in advance.

  • 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-08T12:19:33+00:00Added an answer on June 8, 2026 at 12:19 pm

    Sounds like you could do:

    // Project both lists (lazily) to a common anonymous type
    var anon1 = list1.Select(foo => new { foo.Id, foo.Information });
    var anon2 = list2.Select(bar => new { bar.Id, bar.Information });
    
    var map = anon1.Concat(anon2).ToDictionary(x => x.Id, x => x.Information);
    

    (You could do all of this in one statement, but I think it’s clearer this way.)

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

Sidebar

Related Questions

I have two related classes which share a common interface and are both stored
I have two classes (MVC view model) which inherits from one abstract base class.
I have a class that instantiates two classes which implement interfaces. I want one
I have two async classes in my application which you can see below class
I have a MustInherit Parent class with two Child classes which Inherit from the
I have two classes class PopulationMember { public: void operationOnThisMember1(); void operationOnThisMember2(); ... private:
the summary of my question is I have 2 classes which share a common
I want to share some information between two classes (A and B), which are
Suppose I have these two objects: public class Object1 { string prop1; string prop2;
I have two classes which share the identical methods and I would like to

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.