using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ListlistOfItems = new List ();
listOfItems.Add(4);
listOfItems.Add(2);
listOfItems.Add(3);
listOfItems.Add(1);
listOfItems.Add(6);
listOfItems.Add(4);
listOfItems.Add(3);
var duplicates = listOfItems
.GroupBy(i => i)
.Select(g => g.Key);
foreach (var d in duplicates)
{
Console.WriteLine(d);
}
Console.ReadLine();
}
}
}
Out put :
4
2
3
1
6
I guess List.Distinct() would also do.
ReplyDelete