Errore del compilatore CS0163

Aggiornamento: novembre 2007

Messaggio di errore

Il controllo non può passare da un'etichetta case ('etichetta') a un'altra.
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, you must explicitly terminate the case by using one of the following keywords:

  • return

  • goto

  • break

  • throw

  • continue

Se si desidera implementare il "passaggio", utilizzare goto case #. Per ulteriori informazioni, vedere switch (Riferimenti per C#)

Il seguente codice di esempio genera l'errore 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;
      }
   }
}