Linq 在两个列表中查找差异 [英] Linq find differences in two lists

查看:9
本文介绍了Linq 在两个列表中查找差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个这样的成员列表:

I have two list of members like this:

之前:彼得、肯、朱莉娅、汤姆

Before: Peter, Ken, Julia, Tom

之后:彼得、罗伯特、朱莉娅、汤姆

After: Peter, Robert, Julia, Tom

如您所见,Ken 出局,Robert 入局.

As you can see, Ken is is out and Robert is in.

我想要的是检测变化.我想要两个列表中发生变化的列表.linq 对我有什么帮助?

What I want is to detect the changes. I want a list of what has changed in both lists. How can linq help me?

推荐答案

您的问题没有完全指定,但我假设您正在寻找集合中的差异(也就是说,排序无关紧要).如果是这样,您需要两组的 对称差异.您可以使用 Enumerable.Except:

Your question is not completely specified but I assume that you are looking for the differences as sets (that is, ordering does not matter). If so, you want the symmetric difference of the two sets. You can achieve this using Enumerable.Except:

before.Except(after).Union(after.Except(before));

这篇关于Linq 在两个列表中查找差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆