अनुक्रम सेट करें और तत्व जोड़ें।
List<int> ID = new List<int> { 120, 111, 250, 111, 120, 300, 399, 450 }; उपरोक्त सूची से अलग तत्व प्राप्त करने के लिए अलग () विधि का प्रयोग करें।
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 };
// get distinct elements
IEnumerable<int> res = ID.AsQueryable().Distinct();
foreach (int arr in res) {
Console.WriteLine(arr);
}
}
} आउटपुट
120 111 250 300 399 450