Set a sequence and add elements.
List<int> ID = new List<int> { 120, 111, 250, 111, 120, 300, 399, 450 };Use Distinct() method to get distinct element from the above list.
IEnumerable<int> res = ID.AsQueryable().Distinct();
Let us see the complete code.
Example
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);
}
}
}Output
120 111 250 300 399 450