[英]No errors not working two nested for loops in C#
This bugger doesn't work, i cant even check whats wrong because it won't reach the breakpoint. 这个bugger不起作用,我什至无法检查出什么毛病,因为它不会达到断点。 If you set a breakpoint at " Console.WriteLine("breakpoint is never reached");" 如果在“ Console.WriteLine(“从未到达断点”);“处设置断点, it won't trigger the break. 它不会触发中断。 It's simple code, but i can't figure out why it doesn't work. 这是简单的代码,但我不知道为什么它不起作用。 Probably need more sleep :) The ThisPixelCheck function, return true or false if a color is found at a point. 可能需要更多的睡眠:) ThisPixelCheck函数,如果在某个点发现颜色,则返回true或false。 But it's not reached by the code so it seems. 但是看起来它不是代码所能达到的。
void FindPixel()
{
int x = 455;
int y = 1109;
int found = 0;
Color findcolor = ColorTranslator.FromHtml("#FFFFFF");
for (int yplus = 0; yplus > 50; yplus++)
{
for (int xplus = 0; xplus > 50; xplus++)
{
Console.WriteLine("breakpoint is never reached");
var point = new Point(x + xplus, y + yplus);
var foundpixel = ThisPixelCheck(point, findcolor);
if (foundpixel)
{
found += 1;
}
}
status_Label.Text = found.ToString() + " pixels found.";
}
}
void FindPixel()
{
int x = 455;
int y = 1109;
int found = 0;
Color findcolor = ColorTranslator.FromHtml("#FFFFFF");
for (int yplus = 0; yplus < 50; yplus++)
{
for (int xplus = 0; xplus < 50; xplus++)
{
Console.WriteLine("breakpoint is never reached");
var point = new Point(x + xplus, y + yplus);
var foundpixel = ThisPixelCheck(point, findcolor);
if (foundpixel)
{
found += 1;
}
}
status_Label.Text = found.ToString() + " pixels found.";
}
}
the for
loop is wrong. for
循环是错误的。
for (int yplus = 0; yplus > 50; yplus++)
this line yplus is zero and is lower than 50 so programm never goes in the loop. 该行yplus为零且小于50,因此程序永远不会进入循环。 you should try yplus < 50 你应该尝试yplus <50
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.