C# 3.0: Need to return duplicates from a List<>

前端 未结 8 1917
无人及你
无人及你 2020-12-23 19:05

I have a List<> of objects in C# and I need a way to return those objects that are considered duplicates within the list. I do not need the Distinct resultset, I need a

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-23 19:49

    public static IQueryable Duplicates(this IEnumerable source) where TSource : IComparable {

    if (source == null)   
         throw new ArgumentNullException("source");   
     return source.Where(x => source.Count(y=>y.Equals(x)) > 1).AsQueryable();   
    

    }

提交回复
热议问题