static void Main(string[] args) { var phonebook = new PhoneBook(); phonebook.AddContact(new Contact("Andrei", "88005555555", "Moscow")); phonebook.AddContact(new Contact("Masha", "88005555099", "Moscow")); Console.WriteLine(phonebook.FindContact("Andrei")?.Description); Console.WriteLine(phonebook.FindContact("Ivan")?.Description); }
static void Continue() { Console.WriteLine("Would you like to add a name to your phone book? ['Y' for yes, 'Enter 'for no]"); string answer = Console.ReadLine(); if (answer == "Y" || answer == "y") { Console.WriteLine("Enter a name"); string newName = Console.ReadLine(); Console.WriteLine("Enter a number"); string newNumber = Console.ReadLine(); phoneBook.AddContact(newName, newNumber); Continue(); } else { Console.WriteLine("Would you like to look up a number in your phone book? ['Y' for yes, 'Enter 'for no]"); string lookUpAnswer = Console.ReadLine(); if (lookUpAnswer == "Y" || lookUpAnswer == "y") { Console.WriteLine("Enter a name"); string lookUpNumber = Console.ReadLine(); phoneBook.LookUpContact(lookUpNumber); Continue(); } else { Console.WriteLine("Are you finished with the program? ['Y' for yes, 'Enter 'for no]"); string finishedAnswer = Console.ReadLine(); if (finishedAnswer == "Y" || finishedAnswer == "y") { Console.WriteLine("Goodbye."); } else { Continue(); } } } }