比较两个列表,并将不符合要求的列表添加到另一个列表中
本文关键字:列表 添加 另一个 不符合 两个 比较 | 更新日期: 2023-09-27 18:25:07
我想比较两个列表,并将不符合我要求的列表添加到另一个列表中。我真的不知道该怎么做。
我尝试过的:
var componentForThisProject = mdal.Get_MethodComponents_Of_Project(project.Id);
var shapelist = this.diagram.Shapes;
var newlist = (from shape in shapelist
where componentForThisProject.Any(
p =>
p.X_coordinate == Math.Round(shape.Position.X, 0) &&
p.Y_coordinate == Math.Round(shape.Position.Y, 0)
)select shape).ToList();
这项工作,但正如你所看到的,这与我希望它做的相反。它添加了所有匹配的内容。我当然试过把==运算符改成!=但它只是将所有内容添加到我的新列表中。
我正在使用Telerik btw.
有什么想法吗?
这很有效:
var newlist = (from shape in shapelist
where !componentForThisProject.Any(
p =>
p.X_coordinate == Math.Round(shape.Position.X, 0) &&
p.Y_coordinate == Math.Round(shape.Position.Y, 0)
)select shape).ToList();