修复System.Datetime并非所有路径都返回值C#
我想从DateTime计算返回布尔值,但行函数修复System.Datetime并非所有路径都返回值C#,c#,asp.net,C#,Asp.net,我想从DateTime计算返回布尔值,但行函数EnableEdit(DateTime URD)System中有错误。DateTime并非所有路径都返回值。这是我的密码 public static int DayAfterReg(DateTime URD) { int totalDay = (int)(URD - DateTime.Now).TotalDays; return totalDay; } publ
EnableEdit(DateTime URD)
System中有错误。DateTime并非所有路径都返回值。这是我的密码
public static int DayAfterReg(DateTime URD) {
int totalDay = (int)(URD - DateTime.Now).TotalDays;
return totalDay;
}
public static Boolean EnableEdit(DateTime URD)
{
if (UserClass.DayAfterReg(URD)<=3){
return true;
}
else if (UserClass.DayAfterReg(URD) >3)
{
return false;
}
}
public static int DayAfterReg(DateTime URD){
inttotalday=(int)(URD-DateTime.Now).TotalDays;
返回全天;
}
公共静态布尔启用编辑(日期时间URD)
{
if(UserClass.DayAfterReg(URD)3)
{
返回false;
}
}
如何解决它?在那里放一个else:
public static Boolean EnableEdit(DateTime URD)
{
if (UserClass.DayAfterReg(URD) <= 3){
return true;
}
/*else if (UserClass.DayAfterReg(URD) > 3)
{
return false;
}*/
//in your case, you don't need to put an "else if" condition here, it is obvious if first condition(<= 3) is false, then else condition will be " > 3"
else
return false;
}
public静态布尔启用编辑(DateTime URD)
{
if(UserClass.DayAfterReg(URD)3)
{
返回false;
}*/
//在您的情况下,您不需要在此处放置“else-if”条件,如果第一个条件(在此处放置else:
public static Boolean EnableEdit(DateTime URD)
{
if (UserClass.DayAfterReg(URD) <= 3){
return true;
}
/*else if (UserClass.DayAfterReg(URD) > 3)
{
return false;
}*/
//in your case, you don't need to put an "else if" condition here, it is obvious if first condition(<= 3) is false, then else condition will be " > 3"
else
return false;
}
public静态布尔启用编辑(DateTime URD)
{
if(UserClass.DayAfterReg(URD)3)
{
返回false;
}*/
//在您的情况下,您不需要在此处放置“else-if”条件,很明显,如果第一个条件(代码中有一个分支不返回任何值(if 3),那么这是不可能的,因此您可以像这样重写您的方法:
public static Boolean EnableEdit(DateTime URD)
{
return UserClass.DayAfterReg(URD) <= 3;
}
public静态布尔启用编辑(DateTime URD)
{
return UserClass.DayAfterReg(URD)代码中有一个分支不返回任何值(如果为3),但这不是一个可能的情况,因此您可以像这样重写方法:
public static Boolean EnableEdit(DateTime URD)
{
return UserClass.DayAfterReg(URD) <= 3;
}
public静态布尔启用编辑(DateTime URD)
{
return UserClass.DayAfterReg(URD)在EnableEdit的末尾返回一些内容,如果if/else if条件都不是metremove secondif
关键字,您可以将该else if
设置为else
。或者整个方法可以是return UserClass.DayAfterReg(URD)是的,谢谢(y)我忘了在EnableEdit的末尾加上return,以防if/else if条件都不是metremove secondif
关键字你可以把那else if
变成else
。或者整个方法可以是return UserClass.DayAfterReg(URD)是的,谢谢(y)我忘了加上它