惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
爱范儿
爱范儿
量子位
博客园 - 聂微东
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
GbyAI
GbyAI
MyScale Blog
MyScale Blog
IT之家
IT之家
P
Proofpoint News Feed
M
MIT News - Artificial intelligence
The Cloudflare Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Hugging Face - Blog
Hugging Face - Blog
The Register - Security
The Register - Security
Microsoft Security Blog
Microsoft Security Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
Y
Y Combinator Blog
雷峰网
雷峰网
V
Visual Studio Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
博客园 - 叶小钗
D
DataBreaches.Net
B
Blog
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
aimingoo的专栏
aimingoo的专栏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
小众软件
小众软件
腾讯CDC
T
Threat Research - Cisco Blogs
SecWiki News
SecWiki News
Martin Fowler
Martin Fowler
D
Docker
Cisco Talos Blog
Cisco Talos Blog
T
Tenable Blog
Webroot Blog
Webroot Blog
宝玉的分享
宝玉的分享

博客园 - Valens

IIS无法启动:存储空间不足解决办法 做程序员的,平时眼睛总对着代码,很累!看看美女放松放松哦! - Valens - 博客园 How To: Encrypt Configuration Sections in ASP.NET 2.0 Using RSA Mark:使用线程处理(C# 编程指南) LINQ to SQL StepByStep (1) 就事网上线了 About .net Format 【技巧】asp的找不到文件的问题 【翻译】父窗口关闭的时候子窗口也同时关闭 - Valens - 博客园 【翻译】Visual Studio Smart Tag Expansion 小技巧 【翻译】使用ASP.NET 2.0记录错误 ListView提示和技巧 独有数据绑定控件ListView LINQ的标准查询操作符 轻松Web调试、扩展Reflector及更多内容 构建不带Web窗体的Web应用程序_ASP.NET MVC ASP.NET 应用程序的扩展策略 单页界面和AJAX模式 删除Visual Studio IDE最近打开文件和项目列表
交集:通过使用默认的相等比较器对值进行比较生成两个序列的交集
Valens · 2008-12-23 · via 博客园 - Valens

交集:通过使用默认的相等比较器对值进行比较生成两个序列的交集

2008-12-23 11:15  Valens  阅读(315)  评论()    收藏  举报

支持.net 3.5

语法:

public static IEnumerable<TSource> Intersect<TSource>(
    
this IEnumerable<TSource> first,
    IEnumerable
<TSource> second
)

类型参数

TSource

输入序列中的元素的类型。

返回值

类型:System.Collections.Generic..::.IEnumerable<(Of <(TSource>)>)

包含组成两个序列交集的元素的序列。  

此方法通过使用延迟执行实现。即时返回值为一个对象,该对象存储执行操作所需的所有信息。只有通过直接调用对象的 GetEnumerator 方法或使用 Visual C# 中的 foreach(或 Visual Basic 中的 For Each)来枚举该对象时,才执行此方法表示的查询。

集 A 和集 B 的交集定义为包含同时出现在 A 和 B 中的所有元素的集,但不包含任何其他元素。

当枚举此方法返回的对象时,Intersect 将枚举 first,以收集该序列中的所有非重复元素。然后,枚举 second,从而标记那些同时出现在两个序列中的元素。最后,按收集顺序生成标记的元素。

使用默认的相等比较器 Default 对值进行比较。

集 A 和集 B 的交集定义为包含同时出现在 A 和 B 中的所有元素的集,但不包含任何其他元素。

下面的代码示例演示如何使用 Intersect<(Of <(TSource>)>)(IEnumerable<(Of <(TSource>)>), IEnumerable<(Of <(TSource>)>)) 返回同时出现在两个序列中的元素。

int[] id1 = { 442692307138 };
int[] id2 = { 3959834726430 };

IEnumerable

<int> both = id1.Intersect(id2);foreach (int id in both)
    Console.WriteLine(id);
/*
 This code produces the following output:

 26
 30

*/

 http://msdn.microsoft.com/zh-cn/library/bb460136.aspx