How can I fix the error : “Unreachable Code Detected”

后端 未结 4 1659
太阳男子
太阳男子 2020-12-04 00:22
public partial class KalenderLeeftijd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void calBirthDate_SelectionChanged(o         


        
4条回答
  •  旧时难觅i
    2020-12-04 00:59

    The return statement terminates the execution of a function and returns control to the calling function. Execution resumes in the calling function at the point immediately following the call

    If no return statement appears in a function definition, control automatically returns to the calling function after the last statement of the called function is executed

    In Your Code :

    private int CountLeapYears(DateTime startDate)
    {
        int count = 0;
        for (int year = startDate.Year; year <= DateTime.Now.Year; year++)
        {
            if (DateTime.IsLeapYear(year))
            {
                DateTime february29 = new DateTime(year, 2, 29);
                if (february29 >= startDate && february29 <= DateTime.Now.Date)
                {
                    count++;
                }
            }
        }
        return count;//The Execution will be terminated here,the next lines will become unreachable 
        **String** answer = GetAnswer();
        Response.Write(lblAntwoord); 
    }
    }
    

    MSDN LINK :

    C : https://msdn.microsoft.com/en-us/library/sta56yeb.aspx

    c# : https://msdn.microsoft.com/en-us/library/1h3swy84.aspx

提交回复
热议问题