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:10
作者:文/会员上传
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(Language Integrated Query)来求两个集合的交集。下面是一个示例代码:using System;using System.Collections.Generic;using System.Linq;class Program{s
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
在C#中,可以使用LINQ(Language Integrated Query)来求两个集合的交集。下面是一个示例代码:
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 intersection = list1.Intersect(list2);foreach (var num in intersection){Console.WriteLine(num);}}}
在上面的示例中,我们定义了两个整数类型的List集合list1和list2。然后使用Intersect方法来求两个集合的交集,并将结果存储在intersection变量中。最后,使用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