Using LINQ to remove elements from a List

前端 未结 14 2195
抹茶落季
抹茶落季 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:30

    This is a very old question, but I found a really simple way to do this:

    authorsList = authorsList.Except(authors).ToList();
    

    Note that since the return variable authorsList is a List, the IEnumerable returned by Except() must be converted to a List.

提交回复
热议问题