HomeCSharpC# Error CS0102 – The type ‘type name’ already contains a definition for ‘identifier’

C# Error CS0102 – The type ‘type name’ already contains a definition for ‘identifier’

C# Compiler Error

CS0102 – The type ‘type name’ already contains a definition for ‘identifier’

Reason for the Error

You will receive this error when you declare multiple identifiers with the same name with-in the same scope (Eg : same class)

For example, the below code snippet contains the two string fields with-in the class Class1.

namespace DeveloperPublish
{
    class Class1
    {
        string Website1 = "DeveloperPublish";
        string Website1 = "By Senthil Kumar";
    }

    public class Program
    {
        public static void Main()
        {

        }
    }
}

This will result with the error.

Error CS0102 The type ‘Class1’ already contains a definition for ‘Website1’ ConsoleApp2 C:\Users\admin\source\repos\ConsoleApp2\ConsoleApp2\Program.cs 6 Active

Solution

To fix the error, try renaming the duplicate identifier.

Leave a Reply

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