+ 1

Why am I getting an error?

Why am I getting this error: ./Playground/file0.cs(14,25): error CS1002: ; expected https://code.sololearn.com/cJpSdgj226GT/?ref=app

18th Aug 2020, 10:43 PM
•—• • •-• ••• —- -•
•—• • •-• ••• —- -• - avatar
3 Antworten
+ 1
i'm not very good at c# but here is what i can find. while statement use lowercase w. not While but while. ReadLine doesnt take parameter. unlike python in here you need to print the message beforehand last you cant declare same variable inside each case in switch. instead declare it before the switch statement int result = 0 //switch here
18th Aug 2020, 11:43 PM
Rei
Rei - avatar
+ 1
Rei Thanks, you’re right on the 1st and 3rd point. After a few failed attempts, I’ve figured out/come to the conclusion that you can’t, for some reason, reassign variables like you can in Python by redeclaring them. Adding int result=0; before switch statement causes an error. Also, doing int result=0 int result=1 produces an error So I think I meed to get rid of “int” before “result” in the switch statement
19th Aug 2020, 4:36 AM
•—• • •-• ••• —- -•
•—• • •-• ••• —- -• - avatar
+ 1
This is true. In c# a variable is declared once. Redeclaring a varable is not allowed. You can assign another value to the variable as many times you like. 1) int result=3; //declare variable and initialze 2) result=4; //assign another value 3) result=5; //assign another value 4) Console.WriteLine(result);//display value
19th Aug 2020, 6:19 AM
sneeze
sneeze - avatar