Sign in to follow this  

C#: I'm enjoying comparing arrays

This topic is 4517 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Not that I know of. You can check the Length property as a quick initial check. I'd just do the brute force technique for now. Of course, if you're bottlenecked there, you can just construct a hashtable out of one array's elements and use it to check the other's.

Share this post


Link to post
Share on other sites
Ah, thanks.

I'm in the middle of rewqriting a slow tool I had made, and this operation is in the middle of everything. Since I am using arrays, I won't need to do any casting (I'm limited to .NET 1.1).

I'll see if it's still slow as hell once I'm done.

Share this post


Link to post
Share on other sites
1. Compare the hash values for the tables. If they are the same, check using brute-force.
2. When doing brute-force checking, compare the hash values of the objects before checking real equality.

Share this post


Link to post
Share on other sites
Wouldn't that only be shallow equality? I.E. it would return true in this case:

Object[] objects = new Object[10];
Object[] objects2 = objects;

return objects.Equals(objects2) // TRUE;

Wouldn't this be false though?

Object objects = new Object[]{a, b, c};
Object objects2 = new Object[]{a, b, c};

return objects.Equals(objects2) // FALSE


Correct me if I'm wrong.

Share this post


Link to post
Share on other sites
Quote:
Original post by Optus
Wouldn't that only be shallow equality? I.E. it would return true in this case:

Object[] objects = new Object[10];
Object[] objects2 = objects;

return objects.Equals(objects2) // TRUE;

Wouldn't this be false though?

Object objects = new Object[]{a, b, c};
Object objects2 = new Object[]{a, b, c};

return objects.Equals(objects2) // FALSE


Correct me if I'm wrong.


Yep, because arrays are reference types, and I don't think they changed the semantics of Equals.

Share this post


Link to post
Share on other sites

This topic is 4517 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this