get distinct values from array/collection
Published: 9. October 2011 | Updated: 3. November 2011License: Microsoft Public License (MS-PL)
Categories: Framework » Arrays, Collections » Linq
Tags: Array C# Linq
Import namespace
using System.Linq;
Code
int[] numbers = new[] { 5, 5, 10, 15, 15, 30, 100, 100, 100 }; IEnumerable<int> distinct = numbers.Distinct(); foreach (int i in distinct) { Console.WriteLine(i); }Console Output:
5
10
15
30
100
10
15
30
100
| Send us feedback about this snippet » |





