August 21, 2008 01:18 by
admin
Eric White has a post on finding duplicates using LINQ. Here is the sample:
1: int[] listOfItems = new[] { 4, 2, 3, 1, 6, 4, 3 };
2:
3: var duplicates = listOfItems
4: .GroupBy(i => i)
5: .Where(g => g.Count() > 1)
6: .Select(g => g.Key);
7:
8: foreach (var d in duplicates) {
9: Console.WriteLine(d);
10: }
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5