所以你可以准确地解释你的 3 个不同的夏季课程,我认为有条件的方法会更有意义。如果您实现任何类型的递增方法并将未正确排序的数据传递给此方法,则可以将日期或学期 id 匹配时标记ActiveSemster
为"Summer I"
"Summer II"
您可以将条件直接包含在 LINQ 查询中,也可以创建一个方法来根据日期或学期 id 识别夏季
return activeSemester.Select(c => new ActiveSemester
{
id = c.SemesterId,
name = c.Name == "Summer" ? GetSummmer(c.StartDate, c.EndDate) : c.Name
}).ToList();
private string GetSummer(DateTime startDate, DateTime endDate)
{
if (startDate == summer1Start || endDate == summer1End)
return "Summer I";
if (startDate == summer2Start || endDate == summer2End)
return "Summer II";
if (startDate == summer3Start || endDate == summer3End)
return "Summer III";
return "Unknown Summer";
}
private string GetSummer(Integer semesterId)
{
if (semesterId == summer1Id)
return "Summer I";
if (semesterId == summer2Id)
return "Summer II";
if (semesterId == summer3Id)
return "Summer III";
return "Unknown Summer";
}