C
C#15mo 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
Buddy15mo 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
MRW419OP15mo ago
Oh, why is that?
Buddy
Buddy15mo ago
It's just how they designed the language. It is used to distinguish the case labels from code blocks
Iron
Iron15mo ago
Yes in switch case use
:
:
break with
;
;
Sunny99
Sunny9915mo 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
Accord15mo 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.

Did you find this page helpful?