【发布时间】:2012-06-21 19:26:57
【问题描述】:
这很奇怪,因为据我所知,该方法确实返回了一个值或 null...我之前使用 null 运行过它并且它有效...自从我在 if 语句中输入了这 2 个 if 语句,我收到错误“并非所有代码路径都有返回值”
if (dt.Rows.Count != 0)
{
if (dt.Rows[0]["ReportID"].ToString().Length > 40)
{
string ReportID = dt.Rows[0]["ReportID"].ToString().Substring(0, 36);
string ReportIDNumtwo = dt.Rows[0]["ReportID"].ToString().Substring(36, 36);
MyGlobals1.versionDisplayTesting = ReportID;
MyGlobals1.secondversionDisplayTesting = ReportIDNumtwo;
return ReportID;
}
else if (dt.Rows[0]["ReportID"].ToString().Length < 39)
{
string ReportID = dt.Rows[0]["ReportID"].ToString();
MyGlobals1.versionDisplayTesting = ReportID;
return ReportID;
}
}
else
{
return null;
}
}
【问题讨论】:
-
在
else if之后需要一个else -
报告ID为40怎么办?它不会返回...
-
您在 3 分钟后得到 7 个答案 :-)
-
永远不能是40,它们是预定的字符串长度
-
@Nadal 编译器不知道
标签: c#