递归中的异常,无法退出,即使是抛出异常也不能退出! 你这样递归,这不是try.catch里面套try.catch,然后里面该套try.catch,套无数次。。?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我用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); } } } 龙工已帮忙解决,谢谢! 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; } 恩,还是你的代码问题。我觉的递归完全不用try catch.if (findbottom(currentp)) { return true; } 呵呵 程序运行时报错 treeview绑定数据库 控制日期的格式的问题。 Dictionary的简单问题,送分拉! webBrowser显示图片的问题? HELP~关于UDP,接收数据 大家都来说说学C#那些书不能看,那些书不能看,免得耽误初学者的时间. MATLAB与C#混合编程之生成dll报错的问题 关于Process.Start()的问题 请教:我打算用C#来写一个局域网用的即时通讯工具,不知是否合适,再者请说一下QQ的实现原理(限于局域网) c#2008水晶报表为什么只能打印8页,大于8页的就显示不出来了,也打印不了 如何实现锁定IP??
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); }
}
}
{
//只找上边界
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;
}
我觉的递归完全不用try catch.
if (findbottom(currentp))
{
return true;
} 呵呵