我遇到问题处理我的foreach
循环。我不知道为什么,但是当我调试它时,我的颗粒计数等于零。它应该是103.当我运行该程序时,它不显示任何结果。我的代码中是否遗漏了某些内容?foreach循环计数器不工作
代码:
List<Pellets> pellets = new List<Pellets>();
bool gotPellet = false;
foreach (var pellet in pellets)
{
if (pellet.Visibility == Visibility.Visible)
{
var rectPellet = pellet.GetRect(cnvMain);
var pelletCellPoint = pellet.GetCellPoint();
rectPacman.Intersect(rectPellet);
gotPellet = true;
pellet.Visibility = Visibility.Collapsed;
AddPellet(pellet);
mazeValues[(int)pelletCellPoint.X, (int)pelletCellPoint.Y] = ' ';
break;
}
}
我使用Windows 8 Metro应用C#
你没有调试器吗? – paxdiablo
只是一瞥,'break'会跳出'foreach' –
您删除第一行中的所有颗粒 – Sayse