یک گزارش کامل از نحوه عملکرد این کد بنویس:

namespace TaskManager
{
    public class UserTask
    {
        private Dictionary<string, List<Task>> tasksByTag;
        private Dictionary<DateTime, List<Task>> tasksByDate;

        public UserTask()
        {
            tasksByTag = new Dictionary<string, List<Task>>();
            tasksByDate = new Dictionary<DateTime, List<Task>>();
        }

        public Task this[string tag]
        {
            get
            {
                if (tasksByTag.ContainsKey(tag))
                {
                    return tasksByTag[tag][0];
                }
                else
                {
                    throw new KeyNotFoundException($"Tasks with tag {tag} not found");
                }
            }
            set
            {
                if (!tasksByTag.ContainsKey(tag))
                {
                    tasksByTag[tag] = new List<Task>();
                }
                tasksByTag[tag].Add(value);

                if (!tasksByDate.ContainsKey(value.Date))
                {
                    tasksByDate[value.Date] = new List<Task>();
                }
                tasksByDate[value.Date].Add(value);
            }
        }

        public void AddTask(Task task)
        {
            string tag = task.Tag;
            if (!tasksByTag.ContainsKey(tag))
            {
                tasksByTag[tag] = new List<Task>();
            }
            tasksByTag[tag].Add(task);

            DateTime date = task.Date;
            if (!tasksByDate.ContainsKey(date))
            {
                tasksByDate[date] = new List<Task>();
            }
            tasksByDate[date].Add(task);
        }

        public void DeleteTask(Task task)
        {
            string tag = task.Tag;
            if (tasksByTag.ContainsKey(tag))
            {
                tasksByTag[tag].Remove(task);
            }

            DateTime date = task.Date;
            if (tasksByDate.ContainsKey(date))
            {
                tasksByDate[date].Remove(task);
            }
        }

        public List<Task> SearchTask(string tag)
        {
            if (tasksByTag.ContainsKey(tag))
            {
                return tasksByTag[tag];
            }
            else
            {
                throw new KeyNotFoundException($"Tasks with tag {tag} not found");
            }
        }

        public List<Task> SearchTask(DateTime date)
        {
            if (tasksByDate.ContainsKey(date))
            {
                return tasksByDate[date];
            }
            else
            {
                throw new KeyNotFoundException($"Tasks on {date.ToShortDateString()} not found");
            }
        }

        public List<Task> GetAllTasks()
        {
            return tasksByDate.Values.SelectMany(list => list).ToList();
        }

        public List<string> GetTags()
        {
            return tasksByTag.Keys.ToList();
        }
    }

    public class Task
    {
        private string taskDescription;
        private bool isDone;
        private DateTime date;
        private string tag;
        private TimeSpan time;

        public Task(string taskDescription, bool isDone, DateTime date, string tag, TimeSpan time)
        {
            this.taskDescription = taskDescription;
            this.isDone = isDone;
            this.date = date.Date;
            this.tag = tag;
            this.time = time;
        }

        public string TaskDescription
        {
            get { return taskDescription; }
            set { taskDescription = value; }
        }

        public bool IsDone
        {
            get { return isDone; }
            set { isDone = value; }
        }

        public DateTime Date
        {
            get { return date; }
            set { date = value.Date; }
        }

        public string Tag
        {
            get { return tag; }
            set { tag = value; }
        }

        public TimeSpan Time
        {
            get { return time; }
            set { time = value; }
        }
    }

    public class User
    {
        private string username;
        private string password;
        private UserTask userTask;

        public User(string username, string password)
        {
            this.username = username;
            this.password = password;
            userTask = new UserTask();
        }

        public string Username
        {
            get { return username; }
        }

        public string Password
        {
            get { return password; }
        }

        public UserTask UserTask
        {
            get { return userTask; }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            User john = new User("john", "password123");

            while (true)
            {
                Console.WriteLine("-----------------------------");
                Console.WriteLine("1. Today's Tasks");
                Console.WriteLine("2. All Tasks");
                Console.WriteLine("3. Tags");
                Console.WriteLine("4. New Task");
                Console.WriteLine("5. Exit");

                string choice = Console.ReadLine();

                switch (choice)
                {
                    case "1":
                        try
                        {
                            DisplayTasks(john.UserTask.SearchTask(DateTime.Today));
                        }
                        catch (KeyNotFoundException ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        break;
                    case "2":
                        DisplayTasks(john.UserTask.GetAllTasks());
                        break;
                    case "3":
                        DisplayTags(john.UserTask.GetTags());
                        Console.Write("Enter a tag: ");
                        string tag = Console.ReadLine();
                        try
                        {
                        DisplayTasks(john.UserTask.SearchTask(tag));
                        }
                        catch (KeyNotFoundException ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        break;
                    case "4":
                        Console.Write("Task description: ");
                        string taskDescription = Console.ReadLine();
                        Console.Write("Date (M/d/yyyy): ");
                        DateTime date = DateTime.Parse(Console.ReadLine());
                        Console.Write("Time (hh:mm:ss): ");
                        TimeSpan time = TimeSpan.Parse(Console.ReadLine());
                        Console.Write("Tag: ");
                        string taskTag = Console.ReadLine();

                        Task newTask = new Task(taskDescription, false, date, taskTag, time);
                        john.UserTask.AddTask(newTask);
                        Console.WriteLine("Task added successfully.");
                        break;
                    case "5":
                        Environment.Exit(0);
                        break;
                    default:
                        Console.WriteLine("Invalid choice!");
                        break;
                }
            }
        }

        static void DisplayTasks(List<Task> tasks)
        {
            if (tasks.Count == 0)
            {
                Console.WriteLine("No tasks found!");
            }
            else
            {
                foreach (Task task in tasks)
                {
                    Console.WriteLine($"- {task.TaskDescription} ({task.Date.ToShortDateString()}) [{(task.IsDone ? "Done" : "Not Done")}]");
                }
            }
        }

        static void DisplayTags(List<string> tags)
        {
            Console.WriteLine("Tags:");
            foreach (string tag in tags)
            {
                Console.WriteLine($"- {tag}");
            }
        }
    }

}