C# 在C中不使用两个嵌套for循环没有错误#
这家伙不工作,我甚至不能检查出什么问题,因为它不会到达断点。 如果您在“Console.WriteLine(“breakpoint is never reach”);”设置断点,则不会触发中断。 这是简单的代码,但我不明白为什么它不工作。可能需要更多的睡眠:) ThisPixelCheck函数,如果在某个点上发现颜色,则返回true或false。但代码似乎无法到达它C# 在C中不使用两个嵌套for循环没有错误#,c#,loops,for-loop,C#,Loops,For Loop,这家伙不工作,我甚至不能检查出什么问题,因为它不会到达断点。 如果您在“Console.WriteLine(“breakpoint is never reach”);”设置断点,则不会触发中断。 这是简单的代码,但我不明白为什么它不工作。可能需要更多的睡眠:) ThisPixelCheck函数,如果在某个点上发现颜色,则返回true或false。但代码似乎无法到达它 void FindPixel() { int x = 455; int y = 1109
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 findpix()
{
int x=455;
int y=1109;
int=0;
Color findcolor=ColorTranslator.FromHtml(“#FFFFFF”);
对于(int-yplus=0;yplus<50;yplus++)
{
对于(int-xplus=0;xplus<50;xplus++)
{
WriteLine(“从未到达断点”);
变量点=新点(x+xplus,y+yplus);
var foundpixel=此像素检查(点,findcolor);
如果(像素)
{
发现+=1;
}
}
状态_Label.Text=found.ToString()+“找到像素。”;
}
}
循环的错误
for (int yplus = 0; yplus > 50; yplus++)
这行yplus为零,并且小于50,因此程序永远不会进入循环。
您应该尝试yplus<50如果yplus和xplus都从零开始,那么循环条件永远不会为真。也许你的意思是(int-yplus=0;yplus<50;yplus++)等的?达尼特:我现在要睡觉了,谢谢你的解释。@S.Tacked两者都有。谢谢:我错误地做了一个>而这应该是@S.Tacked的乐趣。如果没有问题,您可以采用该解决方案:p
for (int yplus = 0; yplus > 50; yplus++)