एक अनुक्रम सेट करें और तत्व जोड़ें:
List<int> ID = new List<int> { 120, 111, 250, 111, 120, 300, 399, 450 };
उपरोक्त सूची से विशिष्ट तत्व प्राप्त करने के लिए Distinct() विधि का उपयोग करें:
IEnumerable<int> res = ID.AsQueryable().Distinct();
पूर्ण कोड
using System;
using System.Linq;
using System.Collections.Generic;
class Demo {
static void Main() {
List<int> ID = new List<int> { 120, 111, 250, 111, 120, 300, 399, 450 };
// विशिष्ट तत्व प्राप्त करें
IEnumerable<int> res = ID.AsQueryable().Distinct();
foreach (int arr in res) {
Console.WriteLine(arr);
}
}
}
आउटपुट
120 111 250 300 399 450