Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
修复System.Datetime并非所有路径都返回值C#_C#_Asp.net - Fatal编程技术网

修复System.Datetime并非所有路径都返回值C#

修复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

我想从DateTime计算返回布尔值,但行函数
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 second
if
关键字,您可以将该
else if
设置为
else
。或者整个方法可以是
return UserClass.DayAfterReg(URD)是的,谢谢(y)我忘了在EnableEdit的末尾加上return,以防if/else if条件都不是metremove second
if
关键字你可以把那
else if
变成
else
。或者整个方法可以是
return UserClass.DayAfterReg(URD)是的,谢谢(y)我忘了加上它