Roslyn: Control falls through switch statement case labels

Created on 30 Jan 2015  路  4Comments  路  Source: dotnet/roslyn

This issue was previously reported in the old Roslyn forums.

``` C#
var i = 0;

switch (i)
{
case 0:
Console.WriteLine('0');
case 1:
Console.WriteLine('1');
case 2:
break;
}
```

The code above will compile in both scripting and interactive mode.

In interactive mode, the code will compile even if the break statement is omitted.

_Edited Code for clarity_

Area-Interactive Bug Interactive-Debugging Interactive-ScriptingLogic Resolution-Fixed Tenet-Compatibility Verified

All 4 comments

Fall through switch is insanely useful for high performance code.

@sharwell Nice, didn't know that.
Would that emit a jump statement if the behavior would be fall through? Or better would the JIT find out and do not emit the jump at all?

@redknightlois If I'm not mistaken, the C# compiler will remove unnecessary branch instructions between cases when optimization is enabled (but not when optimization is disabled because it would negatively impact the debugging experience).

Was this page helpful?
0 / 5 - 0 ratings