ms_learn_csharp/028_method_parameters/rsvp_app/Program.cs

45 lines
1.3 KiB
C#
Raw Permalink Normal View History

2024-08-11 14:50:17 -04:00
string[] guest_list = {"Rebecca", "Nadia", "Noor", "Jonte"};
string[] rsvps = new string[10];
int count = 0;
// void RSVP(string name, int party_size, string allergies, bool invite_only) {
void RSVP(string name,
int party_size = 1,
string allergies = "none",
bool invite_only = true) {
if (invite_only) {
bool found = false;
foreach (string guest in guest_list) {
if (guest.Equals(name)) {
found = true;
break;
}
}
if (!found) {
Console.WriteLine($"Sorry, {name} is not on the guest list");
return;
}
}
rsvps[count] = $"Name: {name}," +
$"\tParty Size: {party_size}," +
$"\tAllergies: {allergies}";
count++;
}
void show_RSVPs() {
Console.WriteLine("\nTotal RSVPs:");
for (int i = 0; i < count; i++){
Console.WriteLine(rsvps[i]);
}
}
//RSVP("Rebecca", 1, "none", true);
RSVP("Rebecca");
RSVP("Nadia", 2, "Nuts");
//RSVP("Linh", 2, "none", false);
RSVP(name: "Linh", party_size: 2, invite_only: false);
RSVP("Tony", 1, allergies: "Jackfruit", invite_only: true);
RSVP("Noor", 4, invite_only: false);
RSVP("Jonte", 2, "Stone fruit", false);
show_RSVPs();