Array Equality

  • Thread starter Thread starter Tony Nassar
  • Start date Start date
T

Tony Nassar

Hello, all!

There's no documentation of an overriden Equals() method for arrays, and
there does not seem to be one in fact, since any of these assertions will
crash:
int[] x = { 0, 1 };
int[] y = { 0, 1 };

// System.Diagnostics.Debug.Assert(x == y, "Arrays equal?");
// System.Diagnostics.Debug.Assert(Array.Equals(x, y), "Arrays equal?");
// System.Diagnostics.Debug.Assert(x.Equals(y), "Arrays equal?");

Obviously I can loop through them, but do I have to?



Tony Nassar
The Analysis Corp.
703-208-9630
 
Tony Nassar said:
There's no documentation of an overriden Equals() method for arrays, and
there does not seem to be one in fact, since any of these assertions will
crash:
int[] x = { 0, 1 };
int[] y = { 0, 1 };

// System.Diagnostics.Debug.Assert(x == y, "Arrays equal?");
// System.Diagnostics.Debug.Assert(Array.Equals(x, y), "Arrays equal?");
// System.Diagnostics.Debug.Assert(x.Equals(y), "Arrays equal?");

Obviously I can loop through them, but do I have to?

Yes, I believe you do.
 
Oh, I know I do; don't worry about that. But I must say, it's peculiar that
the '==' operator returns 'false' in this case! A "not implemented
exception" I could understand, but 'false'?
 
Tony Nassar said:
Oh, I know I do; don't worry about that. But I must say, it's peculiar that
the '==' operator returns 'false' in this case! A "not implemented
exception" I could understand, but 'false'?

Why would it *not* return false? It's just using object==, which
compares two references.
 
Back
Top