Remove items from IEnumerable

后端 未结 4 732
醉话见心
醉话见心 2021-01-31 14:25

I have 2 IEnumerable collections.

IEnumerable objectsToExcept 

and

IEnumerable allObjects.
         


        
4条回答
  •  滥情空心
    2021-01-31 15:08

    While the other answers are correct, I have to add that the result of the Except() call can be assigned back to the original variable. That is,

    allObjects = allObjects.Except(objectsToExcept);
    

    Also keep in mind that Except() will produce the set difference of the two collections, so if there are duplicates of the variables to be removed, they will all be removed.

提交回复
热议问题