Comparing Arrays in C#

starwiz

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

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

Any ideas?

Thanks a lot for whatever help you can give,
-Starwiz
 
Ive tried array1.equals(array2), and Array.equals(array1, array2) to no avail, and Ive 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 didnt.

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 couldnt do...anyway, to make a long story short, I just switched to using the new beta of NUnit, and alls well; theyve taken care of what I needed to do.

Thanks for the help,
-Starwiz
 
Back
Top