Get Duplicates from IEnumerable - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

Get Duplicates from IEnumerable

Demo Code


using System.Linq;
using System.Collections.Generic;
using System;// ww  w.  ja  v a2s  . co  m

public class Main{
        public static IEnumerable<T1> GetDuplicates<T1, T2>(this IEnumerable<T1> collection, Func<T1, T2> selector)
    {
      return collection.GroupBy(selector).Where(group => group.Count() > 1).SelectMany(group => group);
    }
}

Related Tutorials