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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:40:15+00:00 2026-06-12T00:40:15+00:00

I have 2 arrays : int[] arr1 = new int[] { 1, 2, 3

  • 0

I have 2 arrays :

        int[] arr1 = new int[] { 1, 2, 3 };
        int[] arr2 = new int[] { 1, 2, 3 };

I need to check if they are equal ( not by ref)

What is the difference between writing :

        Console.WriteLine(arr1.SequenceEqual(arr2)); //true

vs

        IStructuralEquatable eqArray1 = arr1;
        Console.WriteLine(eqArray1.Equals(arr2, StructuralComparisons.StructuralEqualityComparer));  //true

both returns True..

When should I use each ?

  • 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-12T00:40:17+00:00Added an answer on June 12, 2026 at 12:40 am

    The implementation of SequenceEqual is kind of similar::

    using (IEnumerator<TSource> enumerator1 = first.GetEnumerator())
    using (IEnumerator<TSource> enumerator2 = second.GetEnumerator())
    {
        while (enumerator1.MoveNext())
        {
            if (!enumerator2.MoveNext() || !comparer.Equals(enumerator1.Current, enumerator2.Current))
            {
                return false;
            }
        }
    
        if (enumerator2.MoveNext())
        {
            return false;
        }
    }
    
    return true;
    

    This default SequenceEqual method use default EqualityComparer<int>.Default for int which is value equality.

    Array implement IStructuralEquatable with Equal method:

    bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
    {
        if (other == null) return false;
    
        if (!object.ReferenceEquals(this, other))
        {
            Array array = other as Array;
            if ((array == null) || (array.Length != this.Length))
            {
                return false;
            }
            for (int i = 0; i < array.Length; i++)
            {
                object x = this.GetValue(i);
                object y = array.GetValue(i);
    
                if (!comparer.Equals(x, y))
                {
                    return false;
                }
            }
        }
    
        return true;
    }
    

    The IEqualityComparer from input parameter is used, in here you input StructruralEqualityComparer but int does not implement IStructruralEquatable, so it uses default comparer for int which is value equality.

    But, needless to input StructruralEqualityComparer because int is not structural, you should just use:

    (arr1 as IStructuralEquatable).Equals(arr2, EqualityComparer<int>.Default);
    

    It still works. You should use StructruralEqualityComparer if item in array is structrural

    So to sum up, the implementation for both is kind of the same, both iterate two array based on value equality of int to make comparison.

    I would prefer the LINQ verson since it is more readable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 arrays named Arr1 and Arr2 in C#. They are of the
I have two arrays that I create like this: public int GameBoard[][] = new
We need to check if 2 arrays are similar or not. The elements can
I have two arrays: int[] intArray = new int[]{point1,point2,point3,point4}; String[] strArray = new String[]{worda,wordb,wordc,wordd};
Let's say I have two arrays: int[] array1 = new int[2000000]; int[] array2 =
I have two arrays. For example: int[] Array1 = new[] {1, 2, 3, 4,
I want to have two arrays: supplierList - that contains the int ID of
I have an array: int[][] lawn = new int[980][1280]; wich stores the values of
i have an array like below int[] array = new array[n];// n may be
I have an int array which has no elements and I'm trying to check

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.