Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
The generic type already contains a definition

If I try to define the following Pair<A, B> class in C#, I get a compiler error.

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; }
}

The compiler error is:

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'

Where are the conflicting definitions?

Usually, one can define a property with the same name as its type, e.g.:

public Guid Guid { get; }
public Uri Uri { get; }

Why is the compiler complaining about the names A and B?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

It's specified in the "Class members" section in the C# standard. In the current draft-v6 branch:

The name of a type parameter in the type_parameter_list of a class declaration shall differ from the names of all other type parameters in the same type_parameter_list and shall differ from the name of the class and the names of all members of the class.

In other words, you can't get a type parameter the same name as another type parameter or a class member. Here, you have a type parameter called A and a property called A.

The fact that the type of the property is also A is irrelevant; this code gives the same error:

class Broken<T>
{
    public string T { get; set; }
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda