12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
编程知识 时间:2024-12-04 17:03:11
作者:文/会员上传
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
在C#中,可以使用LINQ的Intersect方法来过滤数据。Intersect方法用于返回两个集合的交集,即返回同时存在于两个集合中的元素。以下是一个示例代码,演示如何使用Intersect方法过
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
在C#中,可以使用LINQ的Intersect方法来过滤数据。Intersect方法用于返回两个集合的交集,即返回同时存在于两个集合中的元素。以下是一个示例代码,演示如何使用Intersect方法过滤数据:
using System;using System.Linq;using System.Collections.Generic;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 intersectList = list1.Intersect(list2).ToList();foreach (int num in intersectList){Console.WriteLine(num);}}}
在上面的示例中,我们首先创建了两个包含整数的列表list1和list2。然后使用Intersect方法获取这两个列表的交集,结果存储在intersectList中。最后,遍历intersectList并输出结果。最终的输出结果将包含两个列表中同时存在的元素3、4和5。
11-20
11-19
11-20
11-20
11-20
11-19
11-20
11-20
11-19
11-20
11-19
11-19
11-19
11-19
11-19
11-19