Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace To_Do_List
- {
- class Program
- {
- static void Main(string[] args)
- {
- string path = @"C:ToDoTask.txt";
- Console.WriteLine("To-do program");
- while (true)
- {
- if (Console.ReadLine() == "exit")
- {
- Environment.Exit(0);
- }
- if (Console.ReadLine() == "add")
- {
- Console.WriteLine("Please write your task and then press enter");
- string task = Console.ReadLine();
- Console.WriteLine("Task added");
- try
- {
- StreamWriter sw = new StreamWriter(path);
- sw.WriteLine(task);
- }
- catch
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Error: could not write task to file");
- Console.ResetColor();
- }
- }
- if (Console.ReadLine() == "show")
- {
- try
- {
- Console.WriteLine("Tasks:");
- StreamReader sr = new StreamReader(path);
- if (sr.ReadToEnd() != "")
- {
- Console.WriteLine(sr.ReadToEnd());
- }
- else
- {
- Console.WriteLine("No tasks left");
- }
- }
- catch
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Error: could not read tasks file");
- Console.ResetColor();
- }
- }
- if (Console.ReadLine() == "help")
- {
- Console.WriteLine("Write 'add' to add a new task");
- Console.WriteLine("Write 'show' to see current tasks");
- Console.WriteLine("Write 'exit' to exit program");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement