Comparing Arrays in C#

starwiz

Newcomer
Joined
Jul 2, 2003
Messages
21
Is there a pre-written way to compare objects of type Array in C#? It's easy enough to program, but my program is generating C# code that other people will use, and I really don't want to clutter their code with some basic code that I've written.

I've tried array1.equals(array2), and Array.equals(array1, array2) to no avail, and I've been unable to think of anything else.

Any ideas?

Thanks a lot for whatever help you can give,
-Starwiz
 
I've tried array1.equals(array2), and Array.equals(array1, array2) to no avail, and I've been unable to think of anything else.
First... The function Equals only compare Address of the variable unless you override it. So... what I can suggest you is to write your own function that compare each element of both array to make sure that they are "exactly" equal.

Was it what you intended to do ?
 
I thought MS would have overridden the .equals method for something as simple as an array, but I guess they didn't.

The problem came about because I was writing a program that interfaced with NUnit, and at one point, it needed to compare arrays, which NUnit couldn't do...anyway, to make a long story short, I just switched to using the new beta of NUnit, and all's well; they've taken care of what I needed to do.

Thanks for the help,
-Starwiz
 
Back
Top