इंटरसेक्ट () विधि का उपयोग करके दो सरणियों के बीच सामान्य तत्व खोजें।
हमारे सरणियाँ निम्नलिखित हैं -
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