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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:28:15+00:00 2026-06-15T14:28:15+00:00

I have two List, this complex object has 4 public properties of reference type.

  • 0

I have two List, this complex object has 4 public properties of reference type.
How can i compare one list to another to find if those lists are equal in size and by values.

I have implemented Equals in ComplexObject in order to help with equality checks

public Type1 Type1 { get; set; }
public IEnumerable<Type2> Type2s{ get; set; }
public Type3 Type3{ get; set; }
public Type4 Type4 { get; set; }

public bool Equals(ComplexObject complexObject)
{
    int type2sCount = Type2s.Count();
    return Type1 .Equals(complexObject.Type1) &&
        Type3.Equals(complexObject.Type3) &&
        Type4.Equals(complexObject.Type4) &&
        Type2s.Intersect(complexObject.Type2s).Count() == type2sCount;
}

I need also to print out items that do no fit or have no pair in second list

Thanks

  • 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-15T14:28:16+00:00Added an answer on June 15, 2026 at 2:28 pm

    The simplest approach for the lists would be SequenceEqual, but you need to be careful about nulls:

    public bool Equals(ComplexObject complexObject)
    {
        bool eq = Equals(Type1, complexObject.Type1)
            && Equals(Type3, complexObject.Type3)
            && Equals(Type4, complexObject.Type4);
        if (eq)
        {
            if(Type2s == null)
            {
                if(complexObject.Type2s != null) eq = false;
            } else {
                eq = complexObject.Type2s == null ? false
                   : Type2s.SequenceEqual(complexObject.Type2s);
            }
        }
        return eq;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two questions, actaully... First off, Why cant I do this: List<Object> object
I have a list like this Dim emailList as new List(Of String) emailList.Add(one@domain.com) emailList.Add(two@domain.com)
I have two complex objects of the same type. I want to compare both
I have List of complex object and the complex object contains more than two
I have two array list. Each has list of Objects of type Employee. The
I have two Lists, they look like this <List> ads [0] Headline = Sony
I have two List s of type int where I store point coordinates called
I have two list on my request on jsp. First one is productGroupName, and
Ho I have two list view on a frame layout. I want one overlay
Let's assume I have a list with objects of type Value . Value has

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.