C#Linq相交方法
使用该Intersect()方法查找两个数组之间的公共元素。
以下是我们的数组-
int[] val1 = { 15, 20, 40, 60, 75, 90 };
int[] val2 = { 17, 25, 35, 55, 75, 90 };执行相交。
val1.AsQueryable().Intersect(val2);
让我们看看整个例子。
示例
using System;
using System.Collections.Generic;
using System.Linq;
class Demo {
static void Main() {
int[] val1 = { 15, 20, 40, 60, 75, 90 };
int[] val2 = { 17, 25, 35, 55, 75, 90 };
IEnumerable<int> res = val1.AsQueryable().Intersect(val2);
Console.WriteLine("Intersection of both the lists...");
foreach (int a in res)
Console.WriteLine(a);
}
}输出结果
Intersection of both the lists... 75 90
热门推荐
10 生日祝福语男友妈妈简短
11 离职送别文案祝福语简短
12 宝贝生日祝福语简短独特
13 新年祝福语大全简短感谢
14 火把节祝福语简短
15 妈咪跟我生日祝福语简短
16 给表妹生日祝福语简短
17 谢谢学校老师祝福语简短
18 兔年简短祝福语8字