Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C# Program to get distinct element from a sequence
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
Advertisements
