सामान्य तत्वों को प्राप्त करने के लिए इंटेसेक्ट विधि का प्रयोग करें -
सूचियां बनाएं -
var list1 = new List{99, 87};
var list2 = new List{56, 87, 45, 99}; अब, उपरोक्त सूची से सामान्य तत्वों को प्राप्त करने के लिए इंटरसेक्ट () विधि का उपयोग करें -
list1.Intersect(list2);
यहाँ पूरा कोड है -
उदाहरण
using System.Collections.Generic;
using System.Linq;
using System;
public class Demo {
public static void Main() {
// two lists
var list1 = new List<int>{99, 87};
var list2 = new List<int>{56, 87, 45, 99};
// common values
var res = list1.Intersect(list2);
foreach(int i in res) {
Console.WriteLine(i);
}
}
} आउटपुट
99 87