C# Error CS0163 – Control cannot fall through from one case label (‘label’) to another

C# Compiler Error

CS0163 – Control cannot fall through from one case label (‘label’) to another

Reason for the Error

You will receive this error when you DONOT explicitly terminate a switch statement in C#.

For example, try compiling the below code snippet.

C#

You will receive the error code CS0163 in C# for the above code snippet because the section (case 1 ) is not terminated explicitly using break.

C# Error CS0163 – Control cannot fall through from one case label ('label') to another

Error CS0163 Control cannot fall through from one case label (‘case 1:’) to another ConsoleApp2 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp2\Program.cs 12 Active

Solution

When the switch statement contains multiple cases, it will need to be terminated by one of the following keywords : return, goto, break, throw, continue.

The error in the above code can be fixed by adding break to terminate the case 1 as show below.

C#

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...