public static int Test(int n)
{
if (n < 0) return 1;
if (n == 0) return 2;
if (n > 0) return 3;
}
Compiler (Visual Studio 2010, C# 4.0) says “Not all code paths return a value”. Why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The compiler isn’t looking at your conditions. Even though you are correct that at least one of your if-blocks will run, you still need to refactor to something like this: