首页>>帮助中心>>香港vps服务器的c#中intersect的使用方法是什么

香港vps服务器的c#中intersect的使用方法是什么

2024/4/2 56次

香港vps服务器的C#中,可以使用LINQIntersect方法来获取两个集合的交集。Intersect方法接受一个IEnumerable类型的参数,返回一个包含两个集合交集的新集合。

示例代码如下:

using System;

using System.Collections.Generic;

using System.Linq;

class Program

{

static void Main()

{

List<int> list1 = new List<int> { 1, 2, 3, 4, 5 };

List<int> list2 = new List<int> { 3, 4, 5, 6, 7 };

var intersect = list1.Intersect(list2);

foreach (var num in intersect)

{

Console.WriteLine(num);

}

}

}

复制代码

以上代码会输出交集结果3, 4, 5

一诺网络香港免备案专区,提供「香港增强VPS」和「香港特惠VPS」两种类型的高可用弹性计算服务,搭载新一代英特尔®至强®铂金处理器,接入CN2低延时高速回国带宽线路,网络访问顺滑、流畅。机房网络架构采用了BGP协议的解决方案可提供多线路互联融合网络,使得不同网络运营商线路的用户都能通过最佳路由实现快速访问。香港云VPS低至29/月,购买链接:https://www.enuoidc.com/vps.html?typeid=2