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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:06:54+00:00 2026-05-21T10:06:54+00:00

Basically, I have a struct which contains a number of fields. I’m going to

  • 0

Basically, I have a struct which contains a number of fields. I’m going to be creating two lists containing instances of this struct, and I need to be able to check to see if both lists are identical (i.e., same number of structs and have the same values for all of the fields).

I was looking into the SequenceEqual operator, but that relies on the items in the list having the same reference – they won’t, they’re both coming from different sources.

I could just order the lists by a field, loop through each item in the list, then loop through each field/property in the list and see if it matches in the other list – but it seems a bit overcomplicated. Is there an easier 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-05-21T10:06:55+00:00Added an answer on May 21, 2026 at 10:06 am

    The SequenceEqual operator compares using a comparer and not by reference of the sequences.

    From MSDN: “Determines whether two sequences are equal by comparing the elements by using the default equality comparer for their type.”

    Use the SequenceEqual and implement a IEqualityComparer and you should be fine.

    var areSame = list1.SequenceEqual(list2, new MyStructComparer());
    
    class MyStructComparer : IEqualityComparer<MyStruct> {
        public bool Equals(MyStruct x, MyStruct y) {
            if (Object.ReferenceEquals(x, y)) 
                return true;
            if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
                return false;
            return x.A == y.A && x.B == y.B;
        }
    
        public int GetHashCode(MyStruct myStruct)
        {        
            if (Object.ReferenceEquals(myStruct, null)) 
                return 0;
    
            int hashMyStructA = myStruct.A == null ? 0 : myStruct.A.GetHashCode();
            int hashMyStructB = myStruct.B == null ? 0 : myStruct.B.GetHashCode();
    
            return hashMyStructA ^ hashMyStructB;
        }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically you have two ways for doing this: for (int x = 0; x
I have a list which contains a number of _MEMORY_BASIC_INFORMATION structs nested within mb
I basically have a page which shows a processing screen which has been flushed
Let's suppose I have a struct like this: struct my_struct { int a; int
I have a struct I have written which is supposed to represent an entire
I have a HTTPSystemDefinitions.cs file in C# project which basically describes the older windows
I basically have a Money value type, which consists of Amount and Currency .
I have two structs, in which I'm trying to overwrite a method in the
I have a flash file which is basically an animated TV that flicks through
I have a WCF Service contract which is basically the Publish Subscriber pattern. The

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.