विशिष्ट तत्व प्राप्त करने के लिए, विशिष्ट () विधि का उपयोग करें।
डुप्लिकेट तत्वों के साथ हमारी सूची निम्नलिखित है।
List<int> points = new List<int> { 5, 10, 5, 20, 30, 30, 40, 50, 60, 70 }; अब विशिष्ट तत्व प्राप्त करने के लिए -
points.AsQueryable().Distinct();
आइए देखें पूरा उदाहरण -
उदाहरण
using System;
using System.Linq;
using System.Collections.Generic;
class Demo {
static void Main() {
List<int> points = new List<int> { 5, 10, 5, 20, 30, 30, 40, 50, 60, 70 };
// distict elements from the list
IEnumerable<int> res = points.AsQueryable().Distinct();
foreach (int a in res) {
Console.WriteLine(a);
}
}
} आउटपुट
5 10 20 30 40 50 60 70