Question Error CS0161

BrunoB

Well-known member
Joined
Nov 19, 2022
Messages
96
Programming Experience
Beginner
Hello, according to the official documentation I should remove the word return to solve the problem, but it is absurd, because if I want to show it, how will I remove the return? How do I solve it? Thank you.
1673636341340.png
 
I tried the code from the official documentation and it doesn't throw me the mentioned error, but others. And I tried it both in a class and in Program.cs , why does this happen?
1673827063244.png
 
It's because you pasted the code into one of your methods and you are using on old version of the framework, which the makes you use an old version of the C# language which does not support local functions.

Are you sure you put in the code into a class? Or did you put it into the Main() within that class?
 
it doesn't throw me the mentioned error
Really? That screenshot you have above shows an error CS0161 as the fourth error.
 
It's because you pasted the code into one of your methods and you are using on old version of the framework, which the makes you use an old version of the C# language which does not support local functions.

Are you sure you put in the code into a class? Or did you put it into the Main() within that class?
look this
1673868092879.png
 
the code
C#:
namespace PRUEBAERRORES
{
    class ERRORES
    {

        public static int Main() // CS0161
        {
            int i = 5;
            if (i < 10)
            {
                return i;
            }
            else
            {
                // Uncomment the following line to resolve.
                // return 1;
            }



        }
 
Here's an idea. How about you stop posting screenshots of text in a language other than English and expecting us to either know what it says or type it into a translator ourselves? Stop posting pictures of text. If a screenshot adds value then post that as well but ALWAYS post code and error messages as text, formatted appropriately. If the text you have is in a different language, YOU translate it into English for us. In post #22, you've posted a screenshot of two error messages that refer to line 27 and yet the code doesn't even show line 27. You may not be going out of your way to make this more difficult for us but you're definitely not making any effort to make it easier. Start putting some thought into what you post and maybe we wouldn't have to waste so much of our time and yours. It's crazy that something so basic has taken so long to address but it's because you haven't made a clear post about the problem.
 
The last two error messages are telling you that you are missing a closing brace in your code. Yet again, you simply haven't bothered to read your code properly or compare it to the original source. If you had done that then it would have been obvious what the problem was. Did you even read the error messages? We shouldn't need to fix such basic issues as a missing brace.
 
but it shows other additional errors, why?
Probably because you were rushing, and didn't fully copy the whole code, so you missed off the last two }

Being a software engineer is all about being precise and accurate. Computers are completely intolerant of a lack of attention to detail. Work on being a lot more careful when coding..
 
Or alternatively share the code on dotnetfiddle.net.

For example, there's the code that demonstrates that error CS0161:

For those just browsing and don't want to be bothered going to that link:
C#:
public class Test
{
    public static int Main() // CS0161
    {
        int i = 5;
        if (i < 10)
        {
            return i;
        }
        else
        {
            // Uncomment the following line to resolve.
            // return 1;  
        }
    }
}
 
Here's an idea. How about you stop posting screenshots of text in a language other than English and expecting us to either know what it says or type it into a translator ourselves? Stop posting pictures of text. If a screenshot adds value then post that as well but ALWAYS post code and error messages as text, formatted appropriately. If the text you have is in a different language, YOU translate it into English for us. In post #22, you've posted a screenshot of two error messages that refer to line 27 and yet the code doesn't even show line 27. You may not be going out of your way to make this more difficult for us but you're definitely not making any effort to make it easier. Start putting some thought into what you post and maybe we wouldn't have to waste so much of our time and yours. It's crazy that something so basic has taken so long to address but it's because you haven't made a clear post about the problem.
Yes, sorry, you're right, it's crazy that this has taken so long. Don't think it's cute for me, on the contrary.
Regarding my language, unfortunately the language came from the factory in Spanish, and sometimes, the translator does not translate some words well, sorry.
Another big problem is that, for example, I deleted some lines from VS2019 and it turns out that several { were deleted, absurdly and incredibly.
 
Back
Top Bottom