প্রথমে দুটি লিস্ট তৈরি করুন:
List<int> list1 = new List<int>() {40, 20, 60, 3, 55};
List<int> list2 = new List<int>() {20, 70, 55, 80};
সাধারণ উপাদানগুলো খুঁজে বের করতে Intersect ব্যবহার করুন:
list1.Intersect(list2)
সম্পূর্ণ কোড
using System;
using System.Linq;
using System.Collections.Generic;
namespace Demo {
class Program {
static void Main(string[] args) {
List<int> list1 = new List<int>() {40, 20, 60, 3, 55};
List<int> list2 = new List<int>() {20, 70, 55, 80};
Console.WriteLine("Common elements:");
foreach(int value in list1.Intersect(list2))
Console.WriteLine(value);
}
}
}
আউটপুট
Common elements: 20 55