两个集合中的任何交集

编程入门 行业动态 更新时间:2024-10-25 23:28:17
本文介绍了两个集合中的任何交集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我必须找出两个集合是否有交集,我这样做的方式是使用LINQ的加入获得两个集合的交集,然后我使用任何。但我想知道,是否还有其他更优雅的方式这样做?

解决方案

Enumerable.Intersect 可能是你在看

从MSDN:

int [] id1 = { 44,26,92,30,71,38}; int [] id2 = {39,59,83,47,26,4,30}; IEnumerable< int> both = id1.Intersect(id2); if(both.Any())...

i have to find out whether or not two collections have any intersection, the way that i did that is using LINQ's "Join" to get the Intersection of the two collections and then i use "Any". But i wonder, is there other more "elegant" way of doing this?

解决方案

Enumerable.Intersect is probably what you're looking for.

From MSDN:

int[] id1 = { 44, 26, 92, 30, 71, 38 }; int[] id2 = { 39, 59, 83, 47, 26, 4, 30 }; IEnumerable<int> both = id1.Intersect(id2); if(both.Any())...

更多推荐

两个集合中的任何交集

本文发布于:2023-11-29 18:31:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647246.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!