- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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# Linq Distinct() Method
To get the distinct elements, use the Distinct() method.
The following is our list with duplicate elements.
List<int> points = new List<int> { 5, 10, 5, 20, 30, 30, 40, 50, 60, 70 };
Now to get the distinct elements −
points.AsQueryable().Distinct();
Let us see the entire example −
Example
using System; using System.Linq; using System.Collections.Generic; class Demo { static void Main() { List<int> points = new List<int> { 5, 10, 5, 20, 30, 30, 40, 50, 60, 70 }; // distict elements from the list IEnumerable<int> res = points.AsQueryable().Distinct(); foreach (int a in res) { Console.WriteLine(a); } } }
Output
5 10 20 30 40 50 60 70
Advertisements