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

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