1
我有以下方法:訪問實例字段INF的foreach刪除實例
private void ResolveRiver(IEnumerable<Barge> riverBarges)
{
Barge currentBarge = riverBarges.FirstOrDefault();
if (currentBarge == null) return;
var groupedBarges = riverBarges.Where(b => currentBarge.MileMarker + 0.5d >= b.MileMarker && !b.IsGrouped);
BargeGroup group = new BargeGroup { Barges = groupedBarges };
m_bargeGroups.Add(group);
foreach (Barge barge in group.Barges)
{
barge.IsGrouped = true;
}
IEnumerable<Barge> otherBarges = riverBarges.Except(groupedBarges);
//ResolveRiver(otherBarges);
}
riverBarges
是升序sortered IEnumerable
。在foreach循環group.Barges
爲空之後,我真的很想知道爲什麼會發生這種情況?