C#, absolute beginner getting CS1513 C# } expected error

前端 未结 5 714
深忆病人
深忆病人 2021-01-29 08:52

This is my very first day of programming without having any programming background. I was trying the below code. Please click the below link for the screenshot.

CS1513

相关标签:
5条回答
  • 2021-01-29 09:26

    if we use access specifiers inside the static main function for creating the variables like string, it will give this error.

    for ex:-

    namespace ExamplePrgs
    {
        public class MyTestClass
        {
            public static void Main(string[] args)
            {
                public string check_error;//don't use public here. Delete it, it will not show error
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-29 09:27

    As a fellow beginner, it's important to see these kinds of errors being dealt with here. The fact that it's a ; problem and NOT a } problem as the compiler intimates is vital for novices. I've been looking at a similar thing all morning trying to move sections that I thought were in the wrong place, and it turns out it'll probably be a simple syntax mistake somewhere. The compiler error code in this instance was misleading.

    0 讨论(0)
  • 2021-01-29 09:37

    Your if statement has a semicolon on the end, if you remove that it will compile just fine!

    From

    (uservalue == 1) ;
    {
        //code
    }
    

    To

    (uservalue == 1)
    {
        //code
    }
    
    0 讨论(0)
  • 2021-01-29 09:38

    You have a stray semicolon after your if statement. Because of that, the compiler sees your braces as just defining a random block of code (which is valid) but it doesn't understand why you have an else after that.

    0 讨论(0)
  • 2021-01-29 09:42

    I had the same error, after investigating my code, I noted at the end of my script, I had a " {} " which had no use (essentially), so after I had removed that, my code passed.

    0 讨论(0)
提交回复
热议问题