一个简单的问题!!!!!高手马上就可以解决!

Dangyuhang 2003-04-01 02:48:20
private TreeNode searchtreeview(string year,string month,string day)//如果没有记录,则返回null,有年tny,有月tnm,有日tnd,
{
int cny = tvlog.Nodes[0].Nodes.Count;
if (cny != 0)
{
foreach(TreeNode tny in tvlog.Nodes[0].Nodes)
{
if (year == tny.Text)
{
MessageBox.Show("当前年纪录已经存在");
//查找到年记录存在,继续查找月记录是否存在
foreach(TreeNode tnm in tny.Nodes)
{
if (month == tnm.Text)
{
MessageBox.Show("当前月记录已经存在");//找到月记录,继续查找日记录
foreach(TreeNode tnd in tnm.Nodes)
{
if (day == tnd.Text)
{
MessageBox.Show("找到日记录");
return tnd;
}
else//没有相匹配的日,返回tnm
{
return tnm;
}
}
}
else//如果月记录不存在,则返回tny
{
return tny;
}
}
}
else//没有相匹配的年纪录,返回null
{
return null;
}
}
}
else
{
return null;
}
}

这样一段代码,出现错误:
F:\My Documents\Visual Studio Projects\上网计时\Main.cs(444): “上网计时.FrmMain.searchtreeview(string, string, string)” : 并非所有的代码路径都返回值

我还是看不出来,请大家帮忙.
...全文
32 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dangyuhang 2003-04-01
  • 打赏
  • 举报
回复
谢谢!
Knight94 2003-04-01
  • 打赏
  • 举报
回复
如下就行了
private TreeNode searchtreeview(string year,string month,string day)//如果没有记录,则返回null,有年tny,有月tnm,有日tnd,
{
int cny = tvlog.Nodes[0].Nodes.Count;
if (cny != 0)
{
foreach(TreeNode tny in tvlog.Nodes[0].Nodes)
{
if (year == tny.Text)
{
MessageBox.Show("当前年纪录已经存在");
//查找到年记录存在,继续查找月记录是否存在
foreach(TreeNode tnm in tny.Nodes)
{
if (month == tnm.Text)
{
MessageBox.Show("当前月记录已经存在");//找到月记录,继续查找日记录
foreach(TreeNode tnd in tnm.Nodes)
{
if (day == tnd.Text)
{
MessageBox.Show("找到日记录");
return tnd;
}
else//没有相匹配的日,返回tnm
{
return tnm;
}
}
return tnm;
}
else//如果月记录不存在,则返回tny
{
return tny;
}
}
return tny;
}
else//没有相匹配的年纪录,返回null
{
return null;
}
}
return null;
}
else
{
return null;
}
}
Knight94 2003-04-01
  • 打赏
  • 举报
回复
你每个foreach后都应该返回,由于有时并不进入foreach,原因其不满足,即集合为空。

110,568

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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