除了与 Distinct 有类似的效果? [英] Except has similar effect to Distinct?

查看:44
本文介绍了除了与 Distinct 有类似的效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现 Except() 会从第一个列表中删除第二个列表中的所有元素,但它也具有使返回结果中的所有元素不同的效果.

I just discovered that Except() will remove all elements in the second list from the first, but it also has the effect that it makes all elements in the returned result distinct.

我使用的简单方法是 Where(v => !secondList.Contains(v))

任何人都可以向我解释为什么会出现这种行为,如果可能,请向我指出解释这一点的文档?

Can anyone explain to me why this is the behavior, and if possible point me to the documentation that explains this?

推荐答案

Except 函数状态:

通过使用默认的相等比较器来比较值,产生两个序列的集合差.

Produces the set difference of two sequences by using the default equality comparer to compare values.

两个集合的集合差定义为第一个集合中没有出现在第二个集合中的成员.

The set difference of two sets is defined as the members of the first set that do not appear in the second set.

这里的重要词是set,它是定义的 为:

The important word here is set, which is defined as:

...一种抽象的数据结构,可以存储某些值,没有任何特定的顺序,也没有重复的值...

...an abstract data structure that can store certain values, without any particular order, and no repeated values...

因为 Except 被记录为基于集合的操作,它也具有使结果值不同的效果.

Because Except is documented as a set-based operation, it also has the effect of making the resulting values distinct.

这篇关于除了与 Distinct 有类似的效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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