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

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

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