I would like to compare two collections (in C#), but I\'m not sure of the best way to implement this efficiently.
I\'ve read the other thread about Enumerable.Sequen
If you use Shouldly, you can use ShouldAllBe with Contains.
collection1 = {1, 2, 3, 4};
collection2 = {2, 4, 1, 3};
collection1.ShouldAllBe(item=>collection2.Contains(item)); // true
And finally, you can write an extension.
public static class ShouldlyIEnumerableExtensions
{
public static void ShouldEquivalentTo(this IEnumerable list, IEnumerable equivalent)
{
list.ShouldAllBe(l => equivalent.Contains(l));
}
}
UPDATE
A optional parameter exists on ShouldBe method.
collection1.ShouldBe(collection2, ignoreOrder: true); // true