0

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?

user1899020
  • 13,167
  • 21
  • 79
  • 154

1 Answers1

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