C# Error CS0140 – The label ‘label’ is a duplicate

C# Compiler Error

CS0140 – The label ‘label’ is a duplicate

Reason for the Error

This error is specific to the the usage of goto statement in C#. When you have defined more than one label with-in the same scope, you will receive this error.

For example, try compiling the below C# code snippet.

namespace DeveloperPublishNamespace
{
    public class DeveloperPublish
    {
        public static void Main()
        {          
            goto FirstLabel;
            FirstLabel: System.Console.WriteLine("First Label");
            FirstLabel: System.Console.WriteLine("Second Label");
        }
    }

}

You will receive the C# Error CS0140 because we have defined two labels with the same name “FirstLabel” with-in the Main function.

C# Error CS0140 – The label 'label' is a duplicate

Error CS0140 The label ‘FirstLabel’ is a duplicate ConsoleApp1 C:\Users\SenthilBalu\source\repos\ConsoleApp1\ConsoleApp1\Program.cs 9 Active

Solution

To fix this error, rename the duplicate label to something different from the other label.

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