Skip to content

PRO TIP Block youtube.com at the DNS level — Pi-hole, NextDNS or your hosts file — but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

C# overloaded constructors 🍕

43.9K views on YouTube

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 of parameters.
// name + parameters = signature

Pizza pizza = new Pizza(“stuffed crust”, “red sauce”, “mozzarella”);

Console.ReadKey();
}
}
class Pizza
{
String bread;
String sauce;
String cheese;
String topping;

public Pizza(String bread)
{
this.bread = bread;
}
public Pizza(String bread, String sauce)
{
this.bread = bread;
this.sauce = sauce;
}
public Pizza(String bread, String sauce, String cheese)
{
this.bread = bread;
this.sauce = sauce;
this.cheese = cheese;
}
public Pizza(String bread, String sauce, String cheese, String topping)
{
this.bread = bread;
this.sauce = sauce;
this.cheese = cheese;
this.topping = topping;
}
}
}