Using LINQ to remove elements from a List

前端 未结 14 1993
抹茶落季
抹茶落季 2020-11-22 11:09

Say that I have LINQ query such as:

var authors = from x in authorsList
              where x.firstname == \"Bob\"
              select x;

14条回答
  •  悲哀的现实
    2020-11-22 11:43

    Say that authorsToRemove is an IEnumerable that contains the elements you want to remove from authorsList.

    Then here is another very simple way to accomplish the removal task asked by the OP:

    authorsList.RemoveAll(authorsToRemove.Contains);
    

提交回复
热议问题