C
C#•3y ago
Down

Compiler error [Answered]

So im getting compiler error, i understand what it means but i dont know why i get it can you explain to me?
24 Replies
Down
DownOP•3y ago
im geting this error
Down
DownOP•3y ago
Down
DownOP•3y ago
there why cant i use the same name since its inside other case
Pobiega
Pobiega•3y ago
cases dont create scopes you can manually add a scope thou
Down
DownOP•3y ago
using { }?
Pobiega
Pobiega•3y ago
yes
Down
DownOP•3y ago
okay ill try thought they do thanks
Pobiega
Pobiega•3y ago
yw
Down
DownOP•3y ago
where would i need to add { }?
Pobiega
Pobiega•3y ago
below the case the first one
Down
DownOP•3y ago
yeah and wherei close
Pobiega
Pobiega•3y ago
so wrap all your "case code" in that
Down
DownOP•3y ago
tried and some are coloring in red
ero
ero•3y ago
wait for it pepelaughing
Pobiega
Pobiega•3y ago
var x = 123;
switch (x)
{
case 1:
{
var y = 343;
}
break;
case 2:
{
var y = "hello";
}
break;
}
var x = 123;
switch (x)
{
case 1:
{
var y = 343;
}
break;
case 2:
{
var y = "hello";
}
break;
}
the formatting gets wacky, but you get the point
ero
ero•3y ago
put the break in the scope too what how ugly is that
Pobiega
Pobiega•3y ago
oh lol
Down
DownOP•3y ago
okay all is working fine i forgot to add break at the end
Pobiega
Pobiega•3y ago
🙂
Down
DownOP•3y ago
the scopes work thanks do i close this or sum
Pobiega
Pobiega•3y ago
just type /close
ero
ero•3y ago
i was saying this because by default, VS adds indentations for case blocks
var x = 123;
switch (x)
{
case 1:
{
var y = 343;
break;
}
case 2:
{
var y = "hello";
break;
}
}
var x = 123;
switch (x)
{
case 1:
{
var y = 343;
break;
}
case 2:
{
var y = "hello";
break;
}
}
PISSED
Accord
Accord•3y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server