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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:25:26+00:00 2026-05-29T10:25:26+00:00

I need help finding the most efficient way to merge two in-memory collections with

  • 0

I need help finding the most efficient way to merge two in-memory collections with LINQ-to-Objects. In my case, it’s not a simple join or concat because certain items need to be excluded based on a property value.

Let’s use the following example (not very realistic, but it illustrates what I need):

public abstract class Person
{
    public String Name { get; set; }
}

public class Employee : Person
{
    public DateTime? TerminationDate { get; set; }
}

public class Customer : Person
{
    ...
}

Note, an Employee may also be a Customer.

I have a list of Employees and a list of Customers and want to generate a list of all Persons following these rules:

  1. All Customers that are not also Employees
  2. All Employees that are not also Customer AND are not terminated (TerminationDate == null)
  3. All Persons that are both Customers and Employees AND are not terminated (TerminationDate == null)

What’s the most efficient way to accomplish 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-29T10:25:27+00:00Added an answer on May 29, 2026 at 10:25 am

    While not necessarily incorrect, James’ example is a bit more complicated that I was hoping for and is incomplete as I need a single list as the end result.

    Not sure this is the best solution, either, but here’s what I came up with so far:

    public abstract class Person
    {
        public String Name { get; set; }
    
        public override Boolean Equals(Object other)
        {
            var otherPerson = other as Person;
    
            if (otherPerson == null)
                return false;
    
            return Name.Equals(otherPerson.Name, StringComparison.OrdinalIgnoreCase);
        }
    }
    
    public class Employee : Person
    {
        public DateTime? TerminationDate { get; set; }
    }
    
    public class Customer : Person
    {
        ...
    }
    
    
    public class People
    {
        private IEnumerable<Customer> Customers;
        private IEnumerable<Employee> Employees;
    
        public IEnumerable<Person> GetCurrentPeople()
        {
            // Find all customers that are not employees
            var onlyCustomers = Customers.Except(Employees);
    
            // We only want employees that have not been terminated
            var currentEmployees = Employees.Where(e => e.TerminationDate == null);
    
            // Find all customers that are also employees
            var customerAndEmployees = currentEmployees.Intersect(Customers);
    
            // Now deal with employees that are not customers
            var onlyEmployees = currentEmployees.Except(Customers);
    
            // Join the lists together
            var mergedRules = onlyCustomers.Concat(onlyEmployees).Concat(customerAndEmployees);
    
            return mergedRules;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I need help in finding a way to store ArrayList<HashMap<String,String>> in an Bunble
I need help on regex or preg_match because I am not that experienced yet
I have two tables on different servers, and I'd like some help finding an
I need help finding a viable solution to convert bbcode to html, this is
I need help finding the second Wednesday of the year. Here is what I
I need a little help on finding a tutorial or sample on taking a
I need help in finding a public directory of operating system where I can
I need some help finding a jQuery solution to display multiple images in a
I'm working on a simple game and I need some help to improve my
Need some help finding the max value in a worksheet, I tried with range:

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.