在 C# 中没有错误不工作两个嵌套的循环



这个buger不起作用,我什至无法检查出了什么问题,因为它不会到达断点。 如果在" Console.WriteLine("断点从未到达"(;"设置断点,则不会触发中断。 这是简单的代码,但我无法弄清楚为什么它不起作用。可能需要更多睡眠:) ThisPixelCheck 函数,如果在某个点找到颜色,则返回 true 或 false。但是代码似乎没有到达它。

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.";
}
}

for循环是错误的。

for (int yplus = 0; yplus > 50; yplus++)

这条线 yplus 为零且低于 50,因此程序永远不会进入循环。 你应该试试 yplus <50

最新更新