Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out whether two string arrays are equal to other [duplicate]

Tags:

c#

Possible Duplicate:
Comparing two List<string> for equality

How can I find out whether two arrays of string are equal to each other?

I used this, but it does not work, even though the contents of both are the same.

string[] array1 = new string[]{"A" , "B"}

string[] array2 = new string[]{"A" , "B"}

if(array1 == array2)  // it return false !!!!
{
  // 
}
like image 750
Ata Avatar asked Jun 01 '11 05:06

Ata


1 Answers

If you have access to Linq, use SequenceEqual. Otherwise, simply provide the code to first check if the arrays are equal length, and then if items are equal at each index.

like image 180
2 revs, 2 users 67% Avatar answered Nov 15 '22 05:11

2 revs, 2 users 67%