LINQ Except如何工作? [英] How does LINQ Except work?

查看:69
本文介绍了LINQ Except如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
LINQ在两个列表中发现差异

Possible Duplicate:
LINQ find differences in two lists

我想找到2个系列之间的区别.所以我在LINQ语句中使用Except.但是Except似乎仅在第一个集合长于第二个集合时才起作用.例如,即使两个集合不同,它也不会返回任何结果.

I want to find a difference between 2 series. So I am using Except in the LINQ statement. But Except seems to work only when the first collection is longer than the second. For example this will not return any result, even though the 2 collections are different.

double[] numbers1 = { 2.0, 2.1, 2.2, 2.3, 2.4, 2.5 };
double[] numbers2 = { 2.2 };

IEnumerable<double> onlyInFirstSet = numbers2.Except(numbers1);

任何人都可以确认是否是这种情况吗?如果是这样,我必须在编写查询之前检查集合的长度,因为我不知道哪个集合在编译时会更大.

Can anyone confirm if this is the case? If so, do I have to check the collection lengths before I write the query, because I do not know which collection will be bigger at compile time.

编辑

我想我不清楚我的问题.我不在乎哪个集合包含什么.我只想找到2个收藏夹之间的区别.我该怎么办?

I think I was not clear in my question. I do not care which collection contains what. I just want to find difference between 2 collections. How can I do this?

推荐答案

来自

结果

第一个数组中的数字,而不是第二个数组中的数字: 0 2个 4 6 9

Numbers in first array but not second array: 0 2 4 6 9

这篇关于LINQ Except如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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