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
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
}
}
}
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.
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
}
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.
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.