2010-10-30 119 views

回答

6

你可以使用ShouldContainOnly(IEnumerable<T>)擴展方法。

所以,如果你有2個清單,listAlistB使用:

listA.ShouldContainOnly(listB) 
+0

...但檢查你的對象實現'Equals' appr opriately。 Machine.Specifications查找'IComparable ','IComparable','IEquatable ',然後使用'Comparer .Default'。 – 2011-11-28 15:28:53

+0

將包括項目檢查的順序嗎? – Sly 2015-11-12 09:18:30

3

如果在列表中的項目的順序並不重要,你可以使用

listA.ShouldContainOnly(listB); // both lists must have exactly the same items 
listA.ShouldContain(listB);  // listA must at least contain the items of listB 

如果訂單的項目的事項,你可以使用

listA.ShouldEqual(listB);