static void Main(string[] args) { Console.WriteLine("Welcome to Task List!\r\n"); tasks = new TaskList("Tasks.txt"); tasks.Load(); while (true) { Console.Clear(); // List all the tasks ListTasks(); Console.WriteLine(); Console.WriteLine("What would you like to do?"); Console.WriteLine("(A)dd a task"); Console.WriteLine("(C)omplete a task"); Console.WriteLine("(Q)uit"); string input = Console.ReadLine().Trim().ToUpper(); if (input.Length == 0) { continue; } if (input.Substring(0, 1) == "Q") { break; } int taskNumber; switch (input.Substring(0, 1)) { case "A": // Prompt the user to add a task Task task = GetTaskinfo(); tasks.AddTask(task); break; case "C": taskNumber = GetTaskNumber(); task = tasks.List[taskNumber - 1]; task.Completed = true; tasks.Save(); break; } } }
static void Main(string[] args) { Console.WriteLine("*** Welcome to Task List ***\r\n"); // Create the tasklist by loading in the previously saved tasks, if they exist theGlobalTaskList = new TaskList(@".\Tasks.txt"); theGlobalTaskList.Load(); // Create a loop that will run the menu until the user breaks out by typing "Q" while (true) { // Clear the screen Console.Clear(); // Call the local method which prints the task list on the screen ListTasks(); // Display the menu to the user Console.WriteLine(); Console.WriteLine("What do you want to do?"); Console.WriteLine("(A)dd a task"); Console.WriteLine("(C)omplete a task"); Console.WriteLine("(D)elete a task"); Console.WriteLine("(Q)uit"); // Wait for input from the user string input = Console.ReadLine().Trim().ToUpper(); // If they typed nothing, simply go back to the top of this while and re-display everything. if (input.Length == 0) { continue; } // If the user typed "q", break out of the while loop (exit the program) if (input.Substring(0, 1) == "Q") { break; } // The following switch statement handles the rest of the possible selections from the user. If // the user's selection is not handled below, control will fall to the end of the switch. And the // while loop will start again. Task task; switch (input.Substring(0, 1)) { // Add a task case "A": task = GetTaskInfo(); theGlobalTaskList.AddTask(task); break; // Complete a task case "C": task = SelectATask(); task.Complete = true; theGlobalTaskList.Save(); break; // Delete a task case "D": task = SelectATask(); theGlobalTaskList.RemoveTask(task); break; } } }