Is there any particular reason/example that why would I ever need overloaded constructors?

Why can't I just go
Pizza pizza1 = new Pizza("stuffed crust", "tomato sauce", "american cheese","N/A");
No description
16 Replies
Jimmacle
Jimmacle2mo ago
It's not necessary, you shouldn't have it
Angius
Angius2mo ago
You can use "N/A" if you want
あるホちゃん
あるホちゃんOP2mo ago
oh
Angius
Angius2mo ago
Or an empty string Or make it nullable (as a side note, use string instead of String)
あるホちゃん
あるホちゃんOP2mo ago
so nobody actually uses this in programming?
Jimmacle
Jimmacle2mo ago
What do you mean by this Overloading yes The way you're doing it no
Angius
Angius2mo ago
It's useful and used when needed In your case it doesn't seem needed
あるホちゃん
あるホちゃんOP2mo ago
is there any exsamples?
Jimmacle
Jimmacle2mo ago
Don't use a primary constructor, and have one constructor call the other to avoid duplicating code
あるホちゃん
あるホちゃんOP2mo ago
(i still haven't learn what's a primary constructor yet, maybe I'll comeback later)
canton7
canton72mo ago
There's no primary constructor there?
Angius
Angius2mo ago
Just wonky indentation
Jimmacle
Jimmacle2mo ago
I misread but I'm now even more upset Basic formatting goes a long way to make code readable
あるホちゃん
あるホちゃんOP2mo ago
Bro Code
YouTube
C# overloaded constructors 🍕
C# overloaded constructors tutorial example explained #C# #overloaded #constructors using System; namespace MyFirstProgram { class Program { static void Main(string[] args) { // overloaded constructors = technique to create multiple constructors, // with a different set...
Angius
Angius2mo ago
When it comes to just learning, tutorials often don't give you real-life useful examples So you did everything right regarding constructor overloading You just didn't format your code correctly, which confused Jimmacle And constructor overloading is not necessarily the best way to do something like the pizza here
Jimmacle
Jimmacle2mo ago
The red line covering the closing brace also didn't help

Did you find this page helpful?