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.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Hey, wait!Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.