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