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");
Pizza pizza1 = new Pizza("stuffed crust", "tomato sauce", "american cheese","N/A");

16 Replies
It's not necessary, you shouldn't have it
You can use
"N/A"
if you wantoh
Or an empty string
Or make it nullable
(as a side note, use
string
instead of String
)so nobody actually uses this in programming?
What do you mean by this
Overloading yes
The way you're doing it no
It's useful and used when needed
In your case it doesn't seem needed
is there any exsamples?
Don't use a primary constructor, and have one constructor call the other to avoid duplicating code
(i still haven't learn what's a primary constructor yet, maybe I'll comeback later)
There's no primary constructor there?
Just wonky indentation
I misread but I'm now even more upset
Basic formatting goes a long way to make code readable
did i get something wrong? i'm following this tutorial
https://www.youtube.com/watch?v=OLxIscUoTgY&list=PLZPZq0r_RZOPNy28FDBys3GVP2LiaIyP_&index=35
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...
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
The red line covering the closing brace also didn't help