Task Manager (To-Do List).

Simple To-Do List App in C

This app allows users to add tasks, view their list, mark tasks as completed, and delete tasks. It’s a great project for beginners to practice basic C# concepts.

Key Components of the Code

Namespaces:

using…


This content originally appeared on DEV Community and was authored by Kerimova_Manzura

Simple To-Do List App in C

This app allows users to add tasks, view their list, mark tasks as completed, and delete tasks. It's a great project for beginners to practice basic C# concepts.

Key Components of the Code

  1. Namespaces:

    • using System; and using System.Collections.Generic; are included to use basic features and collections like lists.
  2. Main Class:

    • The Program class contains all the logic for our application.
  3. Task List:

    • We use a List<Task> to store our tasks. This allows dynamic addition and removal of tasks.
  4. Main Loop:

    • A while loop keeps the application running until the user chooses to exit. It clears the console and presents a menu of options.
  5. Adding Tasks:

    • The AddTask method prompts the user to enter a task description, which is then added to the list.
  6. Displaying Tasks:

    • The ShowTasks method shows all tasks with their completion status. If there are no tasks, it informs the user.
  7. Marking Tasks as Completed:

    • In MarkTaskAsDone, the user selects a task by number, and it is marked as completed.
  8. Deleting Tasks:

    • The DeleteTask method allows users to remove a task from the list by selecting its number.
  9. Task Class:

    • The Task class holds the description and status (completed or not) of a task.

Sample Code

Here’s a simplified version of the code:

using System;
using System.Collections.Generic;

namespace TodoListApp
{
    class Program
    {
        static List<Task> tasks = new List<Task>();

        static void Main(string[] args)
        {
            bool exit = false;

            while (!exit)
            {
                Console.Clear();
                Console.WriteLine("Task Manager");
                Console.WriteLine("1. Add a task");
                Console.WriteLine("2. Show task list");
                Console.WriteLine("3. Mark task as completed");
                Console.WriteLine("4. Delete a task");
                Console.WriteLine("5. Exit");

                string input = Console.ReadLine();

                switch (input)
                {
                    case "1": AddTask(); break;
                    case "2": ShowTasks(); break;
                    case "3": MarkTaskAsDone(); break;
                    case "4": DeleteTask(); break;
                    case "5": exit = true; break;
                    default: Console.WriteLine("Invalid input. Try again."); break;
                }
            }
        }

        // Other methods (AddTask, ShowTasks, MarkTaskAsDone, DeleteTask) go here...
    }

    class Task
    {
        public string Description { get; }
        public bool IsDone { get; set; }

        public Task(string description)
        {
            Description = description;
            IsDone = false;
        }
    }
}

Conclusion

This simple To-Do List application is an excellent way to practice your C# skills. You can extend its functionality by adding features like saving tasks to a file or categorizing tasks. Enjoy coding!


This content originally appeared on DEV Community and was authored by Kerimova_Manzura


Print Share Comment Cite Upload Translate Updates
APA

Kerimova_Manzura | Sciencx (2024-09-20T14:16:33+00:00) Task Manager (To-Do List).. Retrieved from https://www.scien.cx/2024/09/20/task-manager-to-do-list/

MLA
" » Task Manager (To-Do List).." Kerimova_Manzura | Sciencx - Friday September 20, 2024, https://www.scien.cx/2024/09/20/task-manager-to-do-list/
HARVARD
Kerimova_Manzura | Sciencx Friday September 20, 2024 » Task Manager (To-Do List).., viewed ,<https://www.scien.cx/2024/09/20/task-manager-to-do-list/>
VANCOUVER
Kerimova_Manzura | Sciencx - » Task Manager (To-Do List).. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/20/task-manager-to-do-list/
CHICAGO
" » Task Manager (To-Do List).." Kerimova_Manzura | Sciencx - Accessed . https://www.scien.cx/2024/09/20/task-manager-to-do-list/
IEEE
" » Task Manager (To-Do List).." Kerimova_Manzura | Sciencx [Online]. Available: https://www.scien.cx/2024/09/20/task-manager-to-do-list/. [Accessed: ]
rf:citation
» Task Manager (To-Do List). | Kerimova_Manzura | Sciencx | https://www.scien.cx/2024/09/20/task-manager-to-do-list/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.