public void GetUserChoice() { Console.Write("\nOption: "); string userChoice = Console.ReadLine(); switch (userChoice) { case "1": //Create new file if user chooses 1 { NewFile file = new NewFile(); file.createNewFile(); break; } case "2": //Open file if user chooses 2 { OpenFile file = new OpenFile(); file.displayFile(); break; } default: //Defaults to re-enter the value if input isn't '1' or '2' { Console.WriteLine("\n****Incorrect Input, enter either 1 for New File or 2 to Open file****"); GetUserChoice(); break; } } }
internal void DisplayMenu(string path) { //Options for various tasks a user can perform Console.WriteLine("\nExit: x\tInsert Line: i\tUpdate Line: u\tNew File: n\tOpen: o"); Console.Write("\nOption: "); string choice = Console.ReadLine(); switch (choice) { case "x": //User pressed x { Environment.Exit(0); break; } case "i": //User pressed i { InsertFileLine file = new InsertFileLine(path); file.InsertLine(); break; } case "u": //User pressed u { UpdateFile file = new UpdateFile(path); file.UpdateLine(); break; } case "n": //User pressed n { NewFile file = new NewFile(); file.createNewFile(); break; } case "o": //User pressed o { OpenFile file = new OpenFile(); file.displayFile(); break; } default: { Console.WriteLine("\nInvalid Input"); DisplayMenu(path); break; } } }