C
C#2y 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
Buddy2y 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
MRW419OP2y ago
Oh, why is that?
Buddy
Buddy2y ago
It's just how they designed the language. It is used to distinguish the case labels from code blocks
Iron
Iron2y ago
Yes in switch case use
:
:
break with
;
;
Sunny99
Sunny992y 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
Accord2y 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?