Edit

Share via


Compiler Error CS0163

Control cannot fall through from one case label ('label') to another

When a switch statement contains more than one switch section, you must explicitly terminate each section, including the last one, by using one of the following keywords:

If you want to implement "fall through" behavior from one section to the next, use goto case #.

The following sample generates CS0163.

// CS0163.cs  
public class MyClass  
{  
    public static void Main()  
    {  
        int i = 0;  
  
        switch (i)   // CS0163  
        {  
            // Compiler error CS0163 is reported on the following line.  
            case 1:  
                i++;  
            // To resolve the error, uncomment one of the following example statements.  
            // return;  
            // break;  
            // goto case 3;  
  
            case 2:  
                i++;  
                return;  
  
            case 3:  
                i = 0;  
                break;  

            default:  
                Console.WriteLine("Default");  
                break;  
        }  
    }  
}

Note that it is correct to have several cases for one implementation, like in the following snippet:

public class MyClass
{
    public static void Main()
    {
        int i = 0;

        switch(i)
        {
            case 1:
            case 2:    // No CS0163
                i++
                break;

            default:
                break;
        }
    }
}