c# - 为什么 Except 函数应用 Distinct?

标签 c#

<分区>

Possible Duplicate:
Except has similar effect to Distinct?

我有两个 List<String>喜欢

lstOne = { "A", "B", "C" ,"C" ,"C" };
lstTwo = { "A" };

lstResult = lstOne.Except(lstTwo).ToList();

现在预期的输出是

lstReult = { "B","C","C","C" };

但是actula结果是这样的

lstResult = { "B","C" };

为什么会这样?我用过Except , 为什么申请 Distinct也是吗?

最佳答案

“除了”是documented作为返回 两个序列的集合差异

集合差按定义是一个集合。根据定义,集合没有重复项。

the expected output is ...

不,预期 输出与实际 输出相同。

如果您期望有所不同,我的建议是调整您的期望以匹配记录在案的行为。

关于c# - 为什么 Except 函数应用 Distinct?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6729432/

相关文章:

c# - 在富文本框中显示行号c#

c# - 在特定时间间隔后执行任务的最佳做法是什么?

c# - 如何使用 BindingSource 在 DataGridView 中绑定(bind)导航属性(二级属性)?

c# - .NET 命名冲突问题中的 SAP Web 服务引用

c# - 在运行时更新应用程序的库 (DLL)?

c# - 如何在 MVC 中刷新页面

c# - 爬虫/机器人如何工作?区分机器人/爬虫 http 请求

c# - 对某些 KeyPress 序列使用 Reactive Extension?

c# - asp :ObjectDataSource?中的TypeName ="API.MyClass+Clients"和TypeName ="API.MyClass.Clients"有什么区别

c# - 在 C# 中忽略异常