Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C中不使用两个嵌套for循环没有错误#_C#_Loops_For Loop - Fatal编程技术网

C# 在C中不使用两个嵌套for循环没有错误#

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

这家伙不工作,我甚至不能检查出什么问题,因为它不会到达断点。 如果您在“Console.WriteLine(“breakpoint is never reach”);”设置断点,则不会触发中断。 这是简单的代码,但我不明白为什么它不工作。可能需要更多的睡眠:) 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 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++)