Skip to content
Home » The type already contains a definition Error

The type already contains a definition Error

To solve The type already contains a definition error follow below methods. The error raised while running the below code sample.

public class Pair<A, B>
{
    public Pair(A a, B b)
    {
        this.A = a;
        this.B = b;
    }

    public A A { get; }
    public B B { get; }
}

ERROR LOG

error CS0102: The type 'Pair<A, B>' already contains a definition for 'A'
error CS0102: The type 'Pair<A, B>' already contains a definition for 'B'

How to solve The type already contains a definition Error ?

The name of a type parameter in a class declaration’s type_parameter_list must differ from the names of all other type parameters in the same type_parameter_list, as well as from the name of the class and the names of all members of the class.

In other words, a type parameter cannot have the same name as another type parameter or a class member. You have a type parameter called A and a property called A in this case.

The fact that the property’s type is also A is irrelevant; this code produces the identical error:

class Broken<T>
{
    public string T { get; set; }
}

Hope the above solution works.

Also read :

Warning: /opt/homebrew/bin is not in your PATH Installing Homebrew On Macos Big Sur
SyntaxError: invalid syntax to repo init in the AOSP code