62,074
社区成员
发帖
与我相关
我的任务
分享
public class Cell : IEquatable<Cell>
{
public bool Equals(Cell other)
{
if (other == null) return false;
if (this == other) return true;
return this.WhatDay == other.WhatDay && this.Lesson == other.Lesson;
}
/// <summary>
/// 星期几
/// </summary>
public int WhatDay { get; set; }
/// <summary>
/// 第几节课
/// </summary>
public int Lesson { get; set; }
}
public class WeekCell
{
public WeekCell()
{
CellList = new List<Cell>();
}
//周
public int Week
{
get;
set;
}
//节次
public List<Cell> CellList
{
get;
set;
}
}
listWeekCell
.GroupBy(weekCell => weekCell.Week)
.Select(item => new WeekCell
{
Week = item.Key,
CellList = item.SelectMany(weekCell => weekCell.CellList).Distinct().ToList()
});
Cell还要重写GetHashCode
public class Cell : IEquatable<Cell>
{
//...
public override int GetHashCode()
{
return this.WhatDay * 33 + this.Lesson;
}
}