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

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...