public static IEnumerable<T> RemovalRepetition<T, R>(this IEnumerable<T> obj, Func<T, R> attribute)
{
return obj.Cast<T>().GroupBy(attribute).Select(w => w.FirstOrDefault());
}private void aa()
{
DataTable dt = new DataTable();
dt.AsEnumerable().RemovalRepetition(w => w.Field<string>("id"));
}
本文介绍了一种使用LINQ去除集合中重复项的方法,通过自定义扩展方法`RemovalRepetition`实现,该方法接受一个源集合及用于确定唯一性的属性选择委托,返回去除重复后的集合。
1339

被折叠的 条评论
为什么被折叠?



