我有2個IEnumerable集合。從IEnumerable刪除項目<T>
IEnumerable<MyClass> objectsToExcept
和
IEnumerable<MyClass> allObjects.
objectsToExcept
可以從allObjects
包含對象。
我需要從allObjects
中刪除objectsToExcept
中的對象。例如:
foreach (var myClass in objectsToExcept)
{
allObjects.Remove(myClass);
}
或者
allObject.Except(objectsToExcept)
但它不工作。方法執行後的計數表明沒有項目被移除。
'Remove'在Linq to XML空間中作爲擴展方法存在,但不執行OP正在嘗試做的事情。奇怪的是,你可以在IEnumerable的成員的文檔頁面上看到它,但它有一個限制'where T:XNode'。技術上'Except'也不在'IEnumerable '上,但這絕對太挑剔。 –
2010-07-06 12:18:26
@Mike二,的確,我從來沒有注意到...它看起來像文檔中的一個錯誤 – 2010-07-06 13:29:48