C# Error CS0152 – The switch statement contains multiple cases with the label value

C# Compiler Error

CS0152 – The switch statement contains multiple cases with the label value

Reason for the Error

You will receive this error when the label is repeated in a switch statement in your C# code.

In the below code snippet, we have the label 1 defined multiple times with-in the switch statement.

namespace ConsoleApp2
{
    class Program
    {
        public static void Main()
        {
            int value = 1;
            switch (value)
            {
                case 1:
                    break;
                case 1:
                    break;
            }
        }
    }
}

This will result with the error code CS0152.

Error CS0152 The switch statement contains multiple cases with the label value ‘1’ ConsoleApp2 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp2\Program.cs 13 Active

C# Error CS0152 – The switch statement contains multiple cases with the label value

Solution

To fix the error, remove the duplicate cases with the label value with-in the switch statement.

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