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

131
Vistas
Why can I have a parameterless constructor and a constructor with only default parameters

Background

I'm working with unity which seems to be serialising classes using some parameterless constructors it creates.

The following code did not properly initialise values:

public WarmthProvider(float initialWarmth = 1)
{
    this.warmth = initialWarmth;
}

My solution looks like this:

public WarmthProvider(float initialWarmth)
{
    this.warmth = initialWarmth;
} 

public WarmthProvider() : this(1)
{

}

(no, this is not in a monobehaviour class)

Question

When implementing this, I noticed the following was perfectly legal and compiled:

public WarmthProvider(float initialWarmth = 1)
{
    this.warmth = initialWarmth;
} 

public WarmthProvider() : this(1)
{

}

Why is this possibly allowed? Surely this is ambiguous as to which constructor to call? Do these not now have the same signature? Is there any reason allowing this syntax is better than it being illegal?

over 4 years ago · Santiago Trujillo
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