你这样递归,这不是try.catch里面套try.catch,然后里面该套try.catch,套无数次。。??

解决方案 »

  1.   

    我用TRY。catch实现抛出异常,好退出,不用也是一样看看下面的。它就是不退出!用BREAK,和return都不行!即使用application.exit(0),都不行,我很郁闷。。
     private void findbottom(Point pt)
            {
                //只找上边界
                      for (int i = 0; i < 8; i++)
                        {
                            currentp.X = pt.X + direct[i].X;
                            currentp.Y = pt.Y + direct[i].Y;
                            nextp.X = pt.X + direct[i + 1].X;
                            nextp.Y = pt.Y + direct[i + 1].Y;                        if (source[nextp.X, nextp.Y] == 0 && source[currentp.X, currentp.Y] == 255)
                            {
                                //线段中断
                                if (i == predot || pt.X >= fourpoint[3].X)
                                {
                                   // break;
                                    return;
                                }
                                bottomxarray[bottomtotal] = currentp.X;
                                bottomyarray[bottomtotal] = currentp.Y;
                                //找到的个数
                                bottomtotal++;
                                //不能这个方向找,线中断了
                                predot = (i + 4) % 8;
                                findbottom(currentp);                        }
                        }
                   
            }
      

  2.   

    龙工已帮忙解决,谢谢! private bool  findbottom(Point pt)
            {
                //只找上边界 
                if (pt.X >= fourpoint[3].X)
                {
                    return true;
                }
                for (int i = 0; i < 8; i++)
                {
                    currentp.X = pt.X + direct[i].X;
                    currentp.Y = pt.Y + direct[i].Y;
                    nextp.X = pt.X + direct[i + 1].X;
                    nextp.Y = pt.Y + direct[i + 1].Y;
                   
                    if (source[nextp.X, nextp.Y] == 0 && source[currentp.X, currentp.Y] == 255)
                    {
                        //线段中断 
                        if (i == predot)
                            return true;
                        bottomxarray[bottomtotal] = currentp.X;
                        bottomyarray[bottomtotal] = currentp.Y;
                        //找到的个数 
                        bottomtotal++;
                        //不能这个方向找,线中断了 
                         predot = (i + 4) % 8;                     if (findbottom(currentp))
                        {
                            return true;
                        }                }
                }            return false;
            } 
      

  3.   

    恩,还是你的代码问题。
    我觉的递归完全不用try catch.
    if (findbottom(currentp))
                        {
                            return true;
                        } 呵呵