Using LINQ to remove elements from a List

前端 未结 14 2112
抹茶落季
抹茶落季 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条回答
  •  -上瘾入骨i
    2020-11-22 11:41

    I think you could do something like this

        authorsList = (from a in authorsList
                      where !authors.Contains(a)
                      select a).ToList();
    

    Although I think the solutions already given solve the problem in a more readable way.

提交回复
热议问题