I have the following code:
private string GetAnswer()
{
....
}
private int CountLeapYears(DateTime startDate)
{
return count;
String answer = GetAnswer();
Response.Write(lblAntwoord);
}
Why do I get the error :
Unreachable code detected
The error is shown on the following line String answer = GetAnswer();
It's just because your code comes after the return statement.
The return statement terminates execution of the method in which it appears and returns control to the calling method. It can also return an optional value. If the method is a void type, the return statement can be omitted.
If the return statement is inside a try block, the finally block, if one exists, will be executed before control returns to the calling method.
http://msdn.microsoft.com/en-us/library/1h3swy84%28v=vs.100%29.aspx
solution (obvious) :
move the unreachable code before the return statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With