How to compare two lists or arrays or list and arrays have the same content? Any easy way to do it? What I can figure out is to loop to compare all the elements one by one. I use the comparison in Unit Test by using Assert? Which Assert
method should I use? Use Assert.AreEqual
?
Asked
Active
Viewed 288 times
0

user1899020
- 13,167
- 21
- 79
- 154
-
1Check this please; http://stackoverflow.com/questions/11055632/how-to-compare-lists-in-unit-testing – Berkay Yaylacı May 22 '16 at 22:34
1 Answers
2
You can use CollectionAssert.AreEqual
.
var a = new[] { 1, 2, };
var b = new[] { 1, 2, };
var c = new[] { 3, 4, };
CollectionAssert.AreEqual(a, b); //passed
CollectionAssert.AreEqual(b, c); //fails
There are other methods on collection assert to help with what you might be asserting about your collections, in case AreEqual
isn't what you want.

DaveShaw
- 52,123
- 16
- 112
- 141