দুটি অ্যারের ছেদ পেতে, Intersect পদ্ধতি ব্যবহার করুন। এটি System.Linq নামস্থান থেকে একটি এক্সটেনশন পদ্ধতি।
পদ্ধতি দুটি অ্যারের মধ্যে সাধারণ উপাদান প্রদান করে।
প্রথমে দুটি অ্যারে সেট করুন -
int[] arr1 = { 44, 76, 98, 34 };
int[] arr2 = { 24, 98, 44, 55, 47, 86 }; এখন উভয় অ্যারে −
-এ ইন্টারসেক্ট ব্যবহার করুনArr1.Intersect(arr2);
নিম্নলিখিত সম্পূর্ণ কোড -
উদাহরণ
using System;
using System.Linq;
class Program {
static void Main() {
int[] arr1 = { 44, 76, 98, 34 };
int[] arr2 = { 24, 98, 44, 55, 47, 86 };
var intersect = arr1.Intersect(arr2);
foreach (int res in intersect) {
Console.WriteLine(res);
}
}
} আউটপুট
44 98