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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:38:15+00:00 2026-05-30T23:38:15+00:00

How to compare two List<MyObject1> with List<MyObject2> ? So if one the Value has

  • 0

How to compare two List<MyObject1> with List<MyObject2>?
So if one the Value has different value it should be possible to check it.

(I know we can use foreach… But I’d like LINQ solution/)

Thank you!

public sealed class MyObject1
{
    public string Name { get; set; }

    public string Value { set; get; }

    public Guid ID { get; set; }
}

public sealed class MyObject2
{
    public string Name { get; set; }

    public string Value { set; get; }

    public Guid ID { get; set; }
}
  • 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-30T23:38:17+00:00Added an answer on May 30, 2026 at 11:38 pm
    public class myComparer: IEqualityComparer  
    {
       public new bool Equals(object x, object y)
       {
          if (x is string )
             return  x ==   y;
          else if (x is Guid ) // maybe you want them to be equal if last char is equal. so you can do it here.
             return   x ==   y;
          else
             return EqualityComparer<object>.Default.Equals(x, y);
       }
    
       public int GetHashCode(object obj)
       {
          return EqualityComparer<object>.Default.GetHashCode(obj);
       }
    }
    

    now

    List<MyObject1 > lst1 = new MyObject1 <MyObject1 >(); 
    //add items here...
    
    List<MyObject2 > lst2 = new MyObject1 <MyObject2 >(); 
    //add items here...
    

    you can equate 2 ways :

    IStructuralEquatable equ = lst1 ;
    
      Console.WriteLine(equ.Equals(lst2 , EqualityComparer<object>.Default));
    
       or
    
       Console.WriteLine(equ.Equals(lst2 , new myComparer()));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I compare the items in two lists and create a new list
I want to compare two List of different lengths and/or same length. The first
Is it possible through SQL in oracle to compare two tables and list the
I want to compare two different types of array list i.e. ArrayList<A> list1 =
I'm trying to compare custom type in two List<T> and use the Intersect /
I am trying to compare two files. I will list the two file content:
I have a List<Foo> , and a compare() method taking two Foo objects and
I want to compare two ms-access .mdb files to check that the data they
I'm trying to find a LINQ expression to compare two list elements. What i
I want to compare two lists. Since we code to interface using List ,

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.