namespace pav.optionalArguments;
class Program
{
public static void printName(string first, string last, bool isMale, string middle = "", bool isMarried = false, bool isDoctor = false)
{
var prefix = isDoctor ? "Dr." : isMale ? "Mr." : isMarried ? "Mrs." : "Ms.";
middle = String.IsNullOrEmpty(middle) ? " " : $" {middle} ";
Console.WriteLine($"{prefix} {first}{middle}{last}");
}
static void Main(string[] args)
{
// no optional parameters needed
printName("Robert", "Smith", true);
// all parameters needed
printName("Jessica", "Johnson", false, "Lyne", true, true);
// mix of named and optional paramters
printName("Megan", "Jones", middle: "Eli", isMale: false, isMarried: true);
//named paramteres not needed, but position matters
printName("Tom", "Williams",
isMale: true, isMarried: true, isDoctor: true);
// jumbled parametar input
printName("Kristy", "Gray", middle: "Grace", isMale: false);
// some sort of logic behind named parametars
printName("Amanda", "Harding", isDoctor: true, isMale: false);
}
}