美文网首页
lambda 根据条件去重

lambda 根据条件去重

作者: 请叫我彭彭 | 来源:发表于2019-08-14 20:36 被阅读0次
        /// <summary>
        /// 去重
        /// </summary>
        public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
        {
            var seenKeys = new HashSet<TKey>();
            return source.Where(element => seenKeys.Add(keySelector(element)));
        }

    相关文章

      网友评论

          本文标题:lambda 根据条件去重

          本文链接:https://www.haomeiwen.com/subject/wxgpnftx.html