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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:01:18+00:00 2026-05-11T20:01:18+00:00

Imagine four lists, all at least have this Id string property, but may have

  • 0

Imagine four lists, all at least have this Id string property, but may have other properties:

public class A //or B, C, D
{
    public string Id { get; set; }
    //..other properties
}

//so:  
List<A> a1 = new List<A>();
List<B> a2 = new List<B>();
List<C> a3 = new List<C>();
List<D> a4 = new List<D>();

I want to select all DISTINCT ids in:
a1, combined with a2, a3 and a4

I thought LINQ syntax would be ideal but how do you combine these to an IEnumerable result with a single string property, for example something with a definition of class A.

  • 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-11T20:01:18+00:00Added an answer on May 11, 2026 at 8:01 pm

    Are they really all lists of the same type? Or do you have

    List<A> a1 = new List<A>();
    List<B> a2 = new List<B>();
    List<C> a3 = new List<C>();
    List<D> a4 = new List<D>();
    

    and you want to combine those because all 4 types have a common string Id property?

    OK, your edit shows I was on the right track. You need an Interface that defines the string Id property and each type A, B, C and D need to implement that Interface.

    Then each list will be of the Interface type and the concat answers will work.

    If you don’t have ability to define the interface, then you could use LINQ to query each list for only the Id field (you should get IQueryable<String> results) and then concat those results.

    Edit: Here’s a LINQ query that should give you what you’re looking for:

    var uniqueIds = (from a in a1
                     select a.Id).Concat(
                     from b in a2
                     select b.Id).Concat(
                     from c in a3
                     select c.Id).Concat(
                     from d in a4
                     select d.Id).Distinct();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine i have this HTML snippet 4 times over for four different sections of
In my code I have often situations like this: public void MyMethod(string data) {
imagine this html on a page <div id=hpl_content_wrap> <p class=foobar>this is one word and
Imagine you have class A which has code which runs as method M. And
Imagine I have two (three, four, whatever) tasks that have to run in parallel.
Imagine a view with, say, 4 subviews, next to each other but non overlapping.
I currently have a page with four list boxes on it and imagine a
Let's imagine I have a relational database in which, among other things, I want
Imagine that I have UserId (actually we do have roughly four columns like userId,
Imagine this scenario: I have a ZPT in Zope where I define, into a

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.