Folks,
I know LINQ has a SequenceEquals method. This method makes sure each item value in each collection matches, in the same order.
What I'm looking for is a more "Equivalent" type of functionality. Just that both sequences contain the same items, not necessarily in the same order.
For example, nUnit has CollectionAssert.AreEqual() and CollectionAssert.AreEquivalent() that do what I'm explaining.
I know that I can do this either by:
- Ordering the lists ahead of time and using SequenceEquals
- Using Intersect, then seeing if the intersection is equal to the original sequence.
I'm so used to LINQ handling all my collection stuff like this that I'm officially getting lazy ;)
Thanks ahead of time!
Edit to give example of answer
var source = new[] {5, 6, 7};
source.Intersect(new[] {5, 7, 6}).Count() == source.Length;
Code came out pretty terse and readable this way, thanks to Toby for answer below!