Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!