Remove items from IEnumerable

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

I have 2 IEnumerable collections.

IEnumerable objectsToExcept 

and

IEnumerable allObjects.
         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-31 15:02

    There is no Remove method on IEnumerable, because it is not meant to be modifiable.

    The Except method doesn't modify the original collection: it returns a new collection that doesn't contain the excluded items:

    var notExcluded = allObjects.Except(objectsToExcept);
    

    See Except on MSDN.

提交回复
热议问题