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

The Archive Base Latest Questions

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

I have two float[] objects. Without writing a for-loop, I want to compare my

  • 0

I have two float[] objects. Without writing a for-loop, I want to compare my two 1D arrays to see if they are equal numerically or not.

When I run the following code (as all elements are equal), it doesn’t go through the if-statement and show the message.

How should I apply the Equals command to work properly?
Is there any compare-command I could use?

 Random r1 = new Random(1);
   int rndNumber= r1.Next(10);
   float[] m = Enumerable.Repeat((float)rndNumber, 180).ToArray();
   float[] m2 = Enumerable.Repeat((float)rndNumber, 180).ToArray();
   if (m.Equals(m2))
    {
    MessageBox.Show("we are equal");
   }
  • 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-15T00:12:08+00:00Added an answer on June 15, 2026 at 12:12 am

    The Equal method for Array isn’t overridden from the default object implementation that just compares the references of the objects (which aren’t equal).

    You want to compare the values of each element in the sequence, and ensure it has the same content in the same order. To do that, use SequenceEqual in System.Linq.Enumerable.

    if(m.SequenceEqual(m2)) {...}
    

    Internally that method will iterate through each element of each sequence and call Equals on each element pair to verify that they are all the same. While this is certainly easier (and arguably more readable) to use than a for loop, keep in mind that it will perform no better than using a for loop, it’s just hiding the loop from you.

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

Sidebar

Related Questions

I have two objects that can be represented as an int, float, bool, or
I have two float variables that are equal, I retrieve them by PHP and
I have a static method that should take two objects and a float as
Synopsis: I have a need to take two generic C# objects, and if they
I have two float values, 'a' and 'b' . I need to calculate the
So, I have two structs: struct coordinate { float x; float y; } struct
I have two columns say Main and Sub . (they can be of same
I have two questions related to function objects and function pointers, Question : 1
I have two variables : count, which is a number of my filtered objects,
I have an Address model that contains two float fields, lat and lng .

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.