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

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