Overloading basically refers to when you have a function implemented a number of times but with different signatures or you have multiple constructors. This let's you define granular functions, methods, or constructors, sometimes this makes sense and sometimes it doesn't.
namespace pav.overloadingFunctions;
class Program
{
public static void printDoctorsName(string first, string middle, string last)
{
middle = String.IsNullOrEmpty(middle) ? " " : $" {middle} ";
Console.WriteLine($"Dr. {first}{middle}{last}");
}
public static void PrintMaleName(string first, string middle, string last)
{
middle = String.IsNullOrEmpty(middle) ? " " : $" {middle} ";
Console.WriteLine($"Mr. {first}{middle}{last}");
}
public static void PrintFemaleName(string first, string middle, string last, bool isMarried)
{
var prefix = isMarried ? "Mrs." : "Ms.";
middle = String.IsNullOrEmpty(middle) ? " " : $" {middle} ";
Console.WriteLine($"{prefix} {first}{middle}{last}");
}
static void Main(string[] args)
{
// no named parametars
PrintMaleName("Robert", "Mike", "Smith");
// named parametars, for obscure values
printDoctorsName("Jessica", "Lyne", "Johnson");
// named paramteres for everything
PrintFemaleName("Megan", "Eli", "Jones", isMarried: true);
// some sort of logic behind named parametars
PrintFemaleName("Amanda", last: "Harding", isMarried: false, middle: "");
}
}