C
C#14mo ago
MRW419

❔ What is the problem with this code?

switch (layer)
{
case Layer.Foreground;
return speed * 1;
case Layer.Middleground;
return speed * 0.5f;
case Layer.Background;
return speed * 0.1f;
default;
return speed * 1;

}
switch (layer)
{
case Layer.Foreground;
return speed * 1;
case Layer.Middleground;
return speed * 0.5f;
case Layer.Background;
return speed * 0.1f;
default;
return speed * 1;

}
No description
6 Replies
Buddy
Buddy14mo ago
instead of semicolon, it's colon after the case example
switch (foo)
{
case Bar:
// Do something
break;
case Foo:
// Do something
break;
default:
// Do something
break;
}
switch (foo)
{
case Bar:
// Do something
break;
case Foo:
// Do something
break;
default:
// Do something
break;
}
MRW419
MRW419OP14mo ago
Oh, why is that?
Buddy
Buddy14mo ago
It's just how they designed the language. It is used to distinguish the case labels from code blocks
Iron
Iron14mo ago
Yes in switch case use
:
:
break with
;
;
Sunny99
Sunny9914mo ago
Without adding break at end of your switch method, you will likely encounter error e.g Switch(later) { case( ToString) foreground: return speed *1; break; case etc .. ... default: return speed *1; break; }
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server