Sign in to follow this  
Daniel Miller

C#: I'm enjoying comparing arrays

Recommended Posts

antareus    576
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
Daniel Miller    218
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
ToohrVyk    1595
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
Optus    422
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
Daniel Miller    218
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

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