- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
- Related Articles
- C++ Program to find out the distinct elements in a given sequence
- C++ Program to Find kth Largest Element in a Sequence
- C# Program to get the smallest and largest element from a list
- C# program to get the last element from an array
- Program to get the last element from an array using C#
- Swift Program to Get a Random Element from the Set
- Get distinct values from a column in MongoDB?
- Python Program to Create a Class and Get All Possible Subsets from a Set of Distinct Integers
- C++ program to find number of distinct values we can get after negating a subarray
- Python program to get average heights of distinct entries
- Get distinct first word from a string with MongoDB?
- MongoDB query to get distinct FirstName values from documents
- C++ Program to get length of longest subsequence in n times copied sequence
- C# Program to return specified number of elements from the beginning of a sequence
- Find total number of distinct years from a string in C++ Program

Advertisements