public static string 五行判断(string 数字)
{
if (数字.EndsWith("1"))
{
return "水";
}
if (数字.EndsWith("6"))
{
return "水";
}
if (数字.EndsWith("2"))
{
return "火";
}
if (数字.EndsWith("7"))
{
return "火";
}
if (数字.EndsWith("3"))
{
return "木";
}
if (数字.EndsWith("8"))
{
return "木";
}
if (数字.EndsWith("4"))
{
return "金";
}
if (数字.EndsWith("9"))
{
return "金";
}
if (数字.EndsWith("0"))
{
return "土";
}
if (数字.EndsWith("5"))
{
return "土";
}
}错误 1 “逻辑关系.BLL双色球数据.五行判断(string)”: 并非所有的代码路径都返回值
这个是什么毛病呢?怎么修改呀
public static string 五行判断(string 数字)
{
if (string.IsNullOrEmpty(数字))
throw new ArgumentException("参数“数字”不合法,不能为null或空串!");
char lastChar = 数字[数字.Length - 1];
switch (lastChar)
{
case '1':
case '6': return "水";
case '2':
case '7': return "火";
//其他的case
default: return string.Empty;
}
}
如果这10个if条件都不成立的话,那么你就没有返回值了。
所以得在最后加上一句:return string.Empty;或return null;
{
if (数字.EndsWith("1"))
{
return "水";
}
if (数字.EndsWith("6"))
{
return "水";
}
if (数字.EndsWith("2"))
{
return "火";
}
if (数字.EndsWith("7"))
{
return "火";
}
if (数字.EndsWith("3"))
{
return "木";
}
if (数字.EndsWith("8"))
{
return "木";
}
if (数字.EndsWith("4"))
{
return "金";
}
if (数字.EndsWith("9"))
{
return "金";
}
if (数字.EndsWith("0"))
{
return "土";
}
if (数字.EndsWith("5"))
{
return "土";
}
return "";
}