我有以下代码在一定程度上有效。但是,问题在于,选秀权数只能增加到球队数量(在这种情况下,只有6支球队,因此选秀权应该在1-6列出)。显然,只做i ++就能让我从1-30变成我。有什么办法只能将数字增加到特定点并重新开始吗?
internal List<Draft> DraftOrder
{
get
{
List<Draft> _draftorder = new List<Draft>();
List<DraftPick> teamPicks = new List<DraftPick>();
foreach (Team t in teams.OrderBy(t => t.winpct))
{
teamPicks.AddRange(t.DraftPicks.Where(s => s.season == season));
}
int i = 1;
foreach (DraftPick d in teamPicks)
{
_draftorder.Add(new Draft
{
team = teams.Find(t => t.teamid == d.currentTeamId).TeamName,
round = d.round,
pick = i++
});
}
return _draftorder;
}
}
答案 0 :(得分:0)
这将为您服务...
internal List<Draft> DraftOrder
{
get
{
List<Draft> _draftorder = new List<Draft>();
List<DraftPick> teamPicks = new List<DraftPick>();
foreach (Team t in teams.OrderBy(t => t.winpct))
{
teamPicks.AddRange(t.DraftPicks.Where(s => s.season == season));
}
int i = 1;
foreach (DraftPick d in teamPicks)
{
_draftorder.Add(new Draft
{
team = teams.Find(t => t.teamid == d.currentTeamId).TeamName,
round = d.round,
pick = i++
});
if(i==6) //ADD CODE
i=1;
}
return _draftorder;
}
}