सबसे पहले दो लिस्ट्स बनाएं -
List list1 = new List() {40, 20, 60, 3, 55};
List list2 = new List() {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 list1 = new List() {40, 20, 60, 3, 55};
List list2 = new List() {20, 70, 55, 80};
Console.WriteLine("Common elements:");
foreach(int value in list1.Intersect(list2))
Console.WriteLine(value);
}
}
}
आउटपुट
Common elements: 20 55