static void Main(string[] args) { bool openBook = true; //Heres an example of Arrays and polymorphism //IMO: Very messy, declaring tons of empty task objects that might not be used. //Also limits how many tasks can be used. Task[] tasks = new Task[100]; tasks[0] = new Task(); tasks[1] = new Task("Zimbabwe", "Fly to zimbabwe"); tasks[2] = new TimedTask("Finish Game UI", "Properly implement buttons and menus systems", DateTime.Now.Add(new TimeSpan(32, 0, 0, 0))); tasks[3] = new Task("Read Book", "Read that one book you havent picked up in over 5 years."); Task teesk = new TimedTask("blah", "polymorphism can get nasty in languages other than python, and even then....", DateTime.Now.Add(new TimeSpan(4, 12, 32, 1))); tasks[0] = teesk; //Replacing the first empty task with a TimedTask. int inpt_num = 0; while (openBook) { Console.WriteLine("\n\n==========Task Book=========="); Console.WriteLine("\tView Tasks: 0\n\tAdd Task: 1\n\tAdd Timed Task: 2\n\tRemove task: 3\n\tQuit: 4"); //Fails neatly int.TryParse(Console.ReadLine(), out inpt_num); switch (inpt_num) { case 0: int i = 0; ShowTasks(tasks, i); break; case 1: AddTask(ref tasks); break; case 2: AddTimedTask(ref tasks); break; case 3: RemoveTask(ref tasks); break; case 4: openBook = false; break; default: Console.WriteLine("Choice invalid, please try again."); break; } } }
public static void AddTimedTask(ref Task[] tasks) { DateTime t_goal = DateTime.Now; TimeSpan time; int days = 0; string t_name = ""; string t_desc = ""; // THE TRY CATCH EXAMPLE try { Console.Write("Your Task: "); t_name = Console.ReadLine(); Console.Write("Task description: "); t_desc = Console.ReadLine(); Console.Write("How many days until the task should be finished?: "); int.TryParse(Console.ReadLine(), out days); time = new TimeSpan(days, 0, 0, 0); t_goal = DateTime.Now.Add(time); } catch (TimeZoneNotFoundException tznfe) { throw tznfe; } catch (System.IO.IOException ioe) { Console.WriteLine($"{ioe.Message}\n Input was incorrect, please try again."); } catch (Exception e) { throw e; } for (int i = 0; i < tasks.Length; i++) { if (tasks[i] == null) { tasks[i] = new TimedTask(t_name, t_desc, t_goal); break; } else if (tasks[i].name == "") { tasks[i] = new TimedTask(t_name, t_desc, t_goal); break; } } }