我相當自豪地製作了我自己的這個LINQ的斷言:斷言都在一個屬於B和所有B屬於一個
bool assert1 = (from e in A
select B.Contains<T>(e, new TComparer()))
.All(x => x == true);
bool assert2 = (from e in B
select A.Contains<T>(e, new TComparer()))
.All(x => x == true);
Assert(assert1 && assert2);
這將檢查A和B是由含有相等相同的元素,即A⊆B和B⊆A.
有沒有更漂亮的方法來做到這一點?
http://stackoverflow.com/questions/1673347/linq-determine-if-two-sequences-contains-exactly-the-same-elements – 2010-01-24 23:59:36