0

Possible Duplicate:
How to find out whether two string arrays are equal to other

how to assert that both lists contain same items?

string[] arr1 = listvalue.ToArray();
string[] arr2 = listvalueMain.ToArray();
for (int i = 0; i < 5; i++)
{
    Assert.AreEqual(arr1[i], arr2[i]);
}

This shows an error.

Community
  • 1
  • 1

3 Answers3

1

You can use SequenceEqual to check that the elements are the same and in the same order.

bool areEqual = listvalue.SequenceEqual(listvalueMain);

or simply

Assert.IsTrue(listvalue.SequenceEqual(listvalueMain));
Yves Rochon
  • 1,492
  • 16
  • 28
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
1

Use CollectionAssert.AreEqual() or other similar method.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
0

You can do like this :

foreach (string item in firstList)  
{  
    if (secondList.Contains(item))  
    {  
        MessageBox.Show("Item found" + item);  
    }
}
abatishchev
  • 98,240
  • 88
  • 296
  • 433