Studies show that good grammar leads to more promotions and higher salaries. Write with Grammarly

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.