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

推荐订阅源

宝玉的分享
宝玉的分享
Recent Commits to openclaw:main
Recent Commits to openclaw:main
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
罗磊的独立博客
V
Visual Studio Blog
爱范儿
爱范儿
H
Help Net Security
J
Java Code Geeks
I
InfoQ
Recent Announcements
Recent Announcements
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recorded Future
Recorded Future
Jina AI
Jina AI
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
GbyAI
GbyAI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
Scott Helme
Scott Helme
S
SegmentFault 最新的问题
S
Securelist
L
LINUX DO - 热门话题
Cyberwarzone
Cyberwarzone
C
Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
T
The Blog of Author Tim Ferriss
博客园_首页
B
Blog
F
Fortinet All Blogs
AWS News Blog
AWS News Blog
V
Vulnerabilities – Threatpost
S
Secure Thoughts
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Schneier on Security
Project Zero
Project Zero
Martin Fowler
Martin Fowler
C
Cybersecurity and Infrastructure Security Agency CISA
N
Netflix TechBlog - Medium
N
News and Events Feed by Topic

博客园 - 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