Thursday, 31 January 2013

Get duplicate items from a list using LINQ

List<String> duplicates = lst.GroupBy(x => x)
                             .Where(g => g.Count() > 1)
                             .Select(g => g.Key)
                             .ToList();

No comments:

Post a Comment