C# Error CS0159 – No such label ‘label’ within the scope of the goto statement

C# Compiler Error

CS0159 – No such label ‘label’ within the scope of the goto statement

Reason for the Error

You will receive this error in C# when you are using a label that is undefined.

The below code snippet demonstrates the C# error code CS0159 as the label “somewhere” is not defined with-in your program.

namespace ConsoleApp2
{
    public class DeveloperPublishException
    {
      
    }
    class Program
    {
        public static void Main()
        {
            goto somewhere;

        }

    }
    
}
C# Error CS0159 – No such label 'label' within the scope of the goto statement

Error CS0159 No such label ‘somewhere’ within the scope of the goto statement ConsoleApp2 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp2\Program.cs 11 Active

Solution

Ensure that the label that you are using with the goto statement is defined with-in the scope where it is called.

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...