我有 OccupancyResultList 列表
List<Occupancy> occupancyResultList = new List<Occupancy>();
占用 的
public partial class Occupancy
{
public Nullable<System.DateTime> on_date { get; set; }
public string type_code { get; set; }
public Nullable<int> available { get; set; }
public Nullable<decimal> rate { get; set; }
public string rate_code { get; set; }
public string publish_flag { get; set; }
}
我想创建另一个列表 on_date,type_code,
不同值Distinct()会生成所有返回重复列的区别结果。
你能给我一个手吗?
提前Thanx!
答案 0 :(得分:1)
您可以使用匿名类型的GroupBy
作为密钥:
occupancyResultList = occupancyResultList
.GroupBy(x => new { x.on_date, x.type_code, x.available })
.Select(g => g.First())
.ToList();
或DistinctBy
方法:
occupancyResultList = occupancyResultList
.DistinctBy(x => new { x.on_date, x.type_code, x.available })
.ToList();