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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:12:47+00:00 2026-06-13T12:12:47+00:00

Say I have a class defined as class Object { public int ID {

  • 0

Say I have a class defined as

class Object
{
    public int ID { get;set; }
    public string Property { get; set; }

    public override bool Equals(object obj)
    {
        Object Item = obj as Object;
        return Item.ID == this.ID;
    }

    public override int GetHashCode()
    {
        int hash = 13;
        hash = (hash * 7) + ID.GetHashCode();
        return hash;       
    }
}

And two lists, defined like so:

List<Object> List1;
List<Object> List2;

These two lists contain objects where ID fields could be the same, but Property fields may or may not. I want to have a result of all objects contained in List1 together with all objects contained in List2, with the condition thatPropertyfield must be set to“1”if it is set to“1”` in any of those lists. The result must contain distinct values (distinct IDs).

For example, if we have 2 lists like this:

List1 
-----  
ID = 0, Property = "1"
ID = 1, Property = ""
ID = 2, Property = "1"
ID = 3, Property = ""

List2
-----
ID = 1, Property = "1"
ID = 2, Property = ""
ID = 3, Property = ""

I need a result to look like this:

Result
-------
ID = 0, Property = "1"
ID = 1, Property = "1"
ID = 2, Property = "1"
ID = 3, Property = "" 

Currently it works like this:

var Result = List1.Except(List2).Concat(List2.Except(List1));
var Intersection = List1.Intersect(List2).ToList();
Intersection.ForEach(x => {
    x.Property = List1.Single(y => y.ID == x.ID).Property == "1" ? "1" : List2.Single(y => y.ID == x.ID).Property == "1" ? "1" : "";
});

Result = Result.Concat(Intersection);

…but ForEach is very slow. Can someone suggest a faster way?

  • 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-13T12:12:48+00:00Added an answer on June 13, 2026 at 12:12 pm
    var result = List1.Concat(List2)
                      .GroupBy(o => o.ID)
                      .Select(g => new Object() { 
                                       ID=g.Key,
                                       Property=g.Any(o=>o.Property=="1")?"1":""
                       })
                      .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user defined class, say import java.util.Calendar; public class Employee{ private String
Let's say I have defined the following class: public abstract class Event { public
Lets say I have model inheritance set up in the way defined below. class
say I have: class Test { public static int Hello = 5; } This
let's say I have class Dummy { String a, b; public Dummy(String a, String
Let's say that I have a boost::variant<std::string, int> myVariant; In this object I keep
Let's say you have a class class C { int * i; public: C(int
Okay, let's say we have a class defined like public class TestClass { private
Suppose we have an object which represent a box. class Box { public: int
Say, I have a simple class Fruit defined as follows: public class Fruit {

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.