Linq find differences in two lists

后端 未结 4 1168
一个人的身影
一个人的身影 2020-12-03 05:05

I have two list of members like this:

Before: Peter, Ken, Julia, Tom

After: Peter, Robert, Julia, Tom

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

4条回答
  •  悲哀的现实
    2020-12-03 05:47

    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));
    

提交回复
热议问题