public bool DrawMenu() { string rawChoice; int choice; bool cont = true; CountryWriter cw = new CountryWriter(path); List <string> countries = cw.ScanFile(path); Console.WriteLine($"{name}, please select an option from our menu:\n1) View list of countries" + $"\n2) Add a country\n3) Exit"); rawChoice = Console.ReadLine(); choice = Validator.CheckInts(rawChoice, 1, 3); Console.WriteLine(); if (choice == 1) { PrintCountries(path); } else if (choice == 2) { cw.AddCountries(countries, path); } else if (choice == 3) { cont = false; } return(cont); }
static void Main(string[] args) { string path = @"C:\Users\slage\Desktop\C# Bootcamp\CountryListApp\countries.txt"; CountryAppMenu menu = new CountryAppMenu(path); CountryWriter cw = new CountryWriter(path); cw.OpenFile(path); bool cont = menu.DrawMenu(); while (cont) { cont = menu.DrawMenu(); } }
public void PrintCountries(string path) { CountryWriter cw = new CountryWriter(path); List <string> countries = new List <string>(); countries = cw.ScanFile(path); for (int i = 0; i < countries.Count; i++) { if (i == 0) { Console.WriteLine(countries[i] + "\n"); } else { Console.WriteLine($"{i}) " + countries[i] + "\n"); } } }