假设我有LINQ查询,例如:
var authors = from x in authorsList
where x.firstname == "Bob"
select x;
Run Code Online (Sandbox Code Playgroud)
鉴于它authorsList是类型List<Author>,我如何删除查询返回的Author元素?authorsListauthors
或者换句话说,如何删除所有名字等于Bob的名字authorsList?
注意:这是用于问题目的的简化示例.
我无法弄清楚如何编写此代码.
我有一个项目列表,这些项目都有ID.还有另一个我们称之为otherID的值.如果otherID为零或null,我们将忽略它.但是,如果otherID包含列表中另一项的ID,我想从列表中删除该项.
例:
item1.ID = 5, item1.otherID = null
item2.ID = 6, item2.otherID = 5
item3.ID = 7, item3.otherID = null
Run Code Online (Sandbox Code Playgroud)
所以应该从列表中删除item1,因为它的ID存在于item2的otherID字段中
谁知道我会怎么写这个?