一个返回值错误~大家看下

dabin130 2008-11-19 11:49:58
//删除文件
protected bool deleteFile(purvey dbpurvey)
{
ad = dbpurvey.purveyimges(dbpurvey);
for (int i = 0; i < ad.Rows.Count; i++)
{
string filename = ad.Rows[i]["imname"].ToString();
string path = Server.MapPath("../../proscenium/userAdmin/pic/") + filename;//定义文件位置。
if (System.IO.File.Exists(path))//文件是否存在
{
try
{
System.IO.File.Delete(path);
return true;
}
catch (Exception)
{
this.Page.ClientScript.RegisterStartupScript(GetType(), "erre", Message.MessageBox("删除失败!"));
return false;
}
}
else
{
this.Page.ClientScript.RegisterStartupScript(GetType(), "erre", Message.MessageBox("该图片不存在!!"));
return false;
}
}
}

错误 并非所有的代码路径都返回值?请教大家了~!谢谢
...全文
54 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
criedshy 2008-11-20
  • 打赏
  • 举报
回复
for 循环外加个return false
criedshy 2008-11-20
  • 打赏
  • 举报
回复
你这个循环只会执行一次,应该不合逻辑
孙晓军82 2008-11-20
  • 打赏
  • 举报
回复
protected bool deleteFile(purvey dbpurvey)
{
ad = dbpurvey.purveyimges(dbpurvey);
for (int i = 0; i < ad.Rows.Count; i++)
{
string filename = ad.Rows[i]["imname"].ToString();
string path = Server.MapPath("../../proscenium/userAdmin/pic/") + filename;//定义文件位置。
if (System.IO.File.Exists(path))//文件是否存在
{
try
{
System.IO.File.Delete(path);
return true;
}
catch (Exception)
{
this.Page.ClientScript.RegisterStartupScript(GetType(), "erre", Message.MessageBox("删除失败!"));
return false;
}
}
else
{
this.Page.ClientScript.RegisterStartupScript(GetType(), "erre", Message.MessageBox("该图片不存在!!"));
return false;
}
}
return true;
}
sz_free_bird 2008-11-20
  • 打赏
  • 举报
回复
如果for循环的条件不成立呢?
所以在for外面加上return

62,269

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧