© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•10mo ago•
6 replies
yourFriend

Silly OOP question about constructors

I am learning OOP and came across this. A way to reuse constructors:
public Dog() : this("NoName") {}

public Dog(string name) : this(name, 1) {}

public Dog(string name, int age) : this(name, age, 0.3) {}

public Dog(string name, int age, double length) : this(name, age, length, new Collar()) {}

public Dog(string name, int age, double length, Collar collar)
{
    this.name = name;
    this.age = age;
    this.length = length;
    this.collar = collar;
}
public Dog() : this("NoName") {}

public Dog(string name) : this(name, 1) {}

public Dog(string name, int age) : this(name, age, 0.3) {}

public Dog(string name, int age, double length) : this(name, age, length, new Collar()) {}

public Dog(string name, int age, double length, Collar collar)
{
    this.name = name;
    this.age = age;
    this.length = length;
    this.collar = collar;
}


I was wondering that can I just use default values for parameters like this, to achieve same result:
public Dog(string name="NoName", int age=1, double length=0.3, Collar collar=new Collar())
{
    this.name = name;
    this.age = age;
    this.length = length;
    this.collar = collar;
}
public Dog(string name="NoName", int age=1, double length=0.3, Collar collar=new Collar())
{
    this.name = name;
    this.age = age;
    this.length = length;
    this.collar = collar;
}


If yes then is their any use case when we would prefer the 1st way over 2nd?
Screenshot_509.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ C# Inheritance Topic Question Mostly about base constructors
C#CC# / help
3y ago
OOP design pattern question
C#CC# / help
2y ago
Exam Prep OOP(Constructors , Inheritance , interface , polymorphism , Exception Handling
C#CC# / help
3y ago
✅ massive question with OOP (beginner)
C#CC# / help
4y ago