扩展类
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