Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0163

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

When a case statement contains one or more statements and is followed by another case statement, one of the following statements must explicitly terminate the case:

  • return
  • goto
  • break

If you want to implement "fall through" behavior, use goto case #.

The following sample generates CS0163:

// CS0163.cs
public class MyClass
{
   public static void Main()
   {
      int i = 0;

      switch (i)   // CS0163
      {
         case 1:
            i++;
            // uncomment one of the following lines to resolve
            // return;
            // break;
            // goto case 3;

         case 2:
            i++;
            return;

         case 3:
            i = 0;
            return;
      }
   }
}
Show:
© 2014 Microsoft