1 out of 2 rated this helpful - Rate this topic

Compiler Error CS0159

No such label 'label' within the scope of the goto statement

The label referenced by the goto statement could not be found within the scope of the goto statement.

The following sample generates CS0159:

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

      switch (i)
      {
         case 1:
            goto case 3;   // CS0159, case 3 label does not exist
         case 2:
            break;
      }
      goto NOWHERE;   // CS0159, NOWHERE label does not exist
   }
}
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ