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:05
作者:文/会员上传
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方法来求两个对象列表的交集。以下是一个示例代码:using System;using System.Collections.Generic;using System.Linq;class Program{static
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
在C#中,可以使用LINQ的Intersect方法来求两个对象列表的交集。以下是一个示例代码:
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 item in intersect){Console.WriteLine(item);}}}
上面的示例代码中,通过调用list1的Intersect方法并传入list2作为参数,就可以得到两个列表的交集。最后,利用foreach循环打印出交集元素。
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