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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:04:37+00:00 2026-05-23T18:04:37+00:00

I have 2 Lists containing entries of a custom class I have created. Basically,

  • 0

I have 2 Lists containing entries of a custom class I have created. Basically, each lists contains a customers orders – but they come from 2 different sources, hence the 2 List’s. Both list’s are the same type however (my custom class), and there is a field to identify which customer the order belongs to.

What I want to do is make a new list, containing each customer that has an order in either of the lists, and the count of the orders from both lists. So, they’ll be 3 fields: The customer’s ID, the number of orders from list 1, and the number of orders from list 2.

I know there’s many ways to do this, but all the ways I’ve thought of seem needlessly complex. Is there a way I can 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-05-23T18:04:38+00:00Added an answer on May 23, 2026 at 6:04 pm

    Something like this would be a good starting point for further tweaks:

    var ordersInList1 = list1.GroupBy(order => order.CustomerId)
                             .ToDictionary(g => g.Key, g => g.Count());
    var ordersInList2 = list2.GroupBy(order => order.CustomerId)
                             .ToDictionary(g => g.Key, g => g.Count());
    
    var results = ordersInList1.Keys.Union(ordersInList2.Keys)
                               .Select(id =>
                               new { 
                                    CustomerId = id, 
                                    CountOrders1 = ordersInList1[id], 
                                    CountOrders2 = ordersInList2[id]
                               })
                               .ToArray();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three unordered lists each containing a subset of a group of items
I have a MySQL MyISAM table containing entries that describe airports. This table contains
I have many variable-sized lists containing instances of the same class with attribute foo,
I have a list of lists containing tuples: [[(1L,)], [(2L,)], [(3L,)], [(4L,)], [(5L,)] how
I have two lists (list1 and list2) containing references to some objects, where some
I have a deep tree structure built with lists, containing lists and floats. I
I'm trying to map a Dictionary containing Lists. I have the following set of
I currently have a code table containing a list of types (Type_ID, Description), but
I have a table lists containing list information like title and id (auto_increment) and
I have two Generic Lists containing different types, for the sake of example, lets

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.