Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda