Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace To_Do_List
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. string path = @"C:ToDoTask.txt";
  15. Console.WriteLine("To-do program");
  16. while (true)
  17. {
  18. if (Console.ReadLine() == "exit")
  19. {
  20. Environment.Exit(0);
  21. }
  22.  
  23. if (Console.ReadLine() == "add")
  24. {
  25. Console.WriteLine("Please write your task and then press enter");
  26. string task = Console.ReadLine();
  27. Console.WriteLine("Task added");
  28. try
  29. {
  30. StreamWriter sw = new StreamWriter(path);
  31. sw.WriteLine(task);
  32. }
  33. catch
  34. {
  35. Console.ForegroundColor = ConsoleColor.Red;
  36. Console.WriteLine("Error: could not write task to file");
  37. Console.ResetColor();
  38. }
  39. }
  40.  
  41. if (Console.ReadLine() == "show")
  42. {
  43. try
  44. {
  45. Console.WriteLine("Tasks:");
  46. StreamReader sr = new StreamReader(path);
  47. if (sr.ReadToEnd() != "")
  48. {
  49. Console.WriteLine(sr.ReadToEnd());
  50. }
  51. else
  52. {
  53. Console.WriteLine("No tasks left");
  54. }
  55. }
  56. catch
  57. {
  58. Console.ForegroundColor = ConsoleColor.Red;
  59. Console.WriteLine("Error: could not read tasks file");
  60. Console.ResetColor();
  61. }
  62. }
  63.  
  64. if (Console.ReadLine() == "help")
  65. {
  66. Console.WriteLine("Write 'add' to add a new task");
  67. Console.WriteLine("Write 'show' to see current tasks");
  68. Console.WriteLine("Write 'exit' to exit program");
  69. }
  70. }
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement