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,332
  • 14
  • 27
Mark Byers
  • 767,688
  • 176
  • 1,542
  • 1,434
1

Use CollectionAssert.AreEqual() or other similar method.

abatishchev
  • 95,331
  • 80
  • 293
  • 426
0

You can do like this :

foreach (string item in firstList)  
{  
    if (secondList.Contains(item))  
    {  
        MessageBox.Show("Item found" + item);  
    }
}
abatishchev
  • 95,331
  • 80
  • 293
  • 426