c#对象集合去重_C# List 对象去重
生活随笔
收集整理的这篇文章主要介绍了
c#对象集合去重_C# List 对象去重
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
扩展类
public static class ObjectExtensions
{
public static IEnumerable DistinctBy(this IEnumerable source, Func keySelector)
{
HashSet seenKeys = new HashSet();
foreach (TSource element in source)
{
if (seenKeys.Add(keySelector(element)))
{
yield return element;
}
}
}
}
对象:
///
/// 返回题目数据
///
[Serializable]
public class QuestionResult
{
///
/// 编号
///
public long Id { get; set; }
///
/// 题目内容
///
public string Title { get; set; }
}
用例:
list.DistinctBy(e => new { e.Id }).ToList();
标签:set,C#,IEnumerable,List,element,对象,static,keySelector,public
来源: https://www.cnblogs.com/wfpanskxin/p/13129627.html
总结
以上是生活随笔为你收集整理的c#对象集合去重_C# List 对象去重的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 中切片工具怎么使用_PS软件中钢笔工具的
- 下一篇: c# ioc 单例模式_Spring-I